Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
package org.apache.rocketmq.broker;

import java.io.File;
import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

import org.apache.rocketmq.common.BrokerConfig;
import org.apache.rocketmq.common.MixAll;
import org.apache.rocketmq.common.UtilAll;
import org.apache.rocketmq.common.future.FutureTaskExt;
import org.apache.rocketmq.remoting.RPCHook;
Expand Down Expand Up @@ -182,4 +184,20 @@ public void testConfigContextMethods() throws Exception {
brokerController.setConfigContext(null);
assertThat(brokerController.getConfigContext()).isNull();
}

@Test
public void testFileReservedTimeWithTrailingWhitespaceIsPreserved() {
Properties properties = new Properties();
properties.setProperty("fileReservedTime", "168 ");
MixAll.properties2Object(properties, messageStoreConfig);

BrokerController brokerController = new BrokerController(
brokerConfig, nettyServerConfig, new NettyClientConfig(), messageStoreConfig);
brokerController.getConfiguration().registerConfig(properties);

Properties allConfigs = MixAll.string2Properties(brokerController.getConfiguration().getAllConfigsFormatString());

assertThat(messageStoreConfig.getFileReservedTime()).isEqualTo(168);
assertThat(allConfigs.getProperty("fileReservedTime")).isEqualTo("168");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ public static void properties2Object(final Properties p, final Object object) {
String key = first.toLowerCase() + tmp;
String property = p.getProperty(key);
if (property != null) {
property = property.trim();
Class<?>[] pt = method.getParameterTypes();
if (pt.length > 0) {
String cn = pt[0].getSimpleName();
Expand All @@ -427,7 +428,6 @@ public static void properties2Object(final Properties p, final Object object) {
} else if (cn.equals("float") || cn.equals("Float")) {
arg = Float.parseFloat(property);
} else if (cn.equals("String")) {
property = property.trim();
arg = property;
} else {
continue;
Expand Down
50 changes: 50 additions & 0 deletions common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,29 @@ public void testProperties2Object() {
assertThat(demoConfig.getDemoName()).isEqualTo("TestDemo");
}

@Test
public void testProperties2ObjectTrimsPrimitiveValues() {
DemoConfig demoConfig = new DemoConfig();
Properties properties = new Properties();
properties.setProperty("demoWidth", " 123 ");
properties.setProperty("demoLength", " 456 ");
properties.setProperty("demoOK", " true ");
properties.setProperty("demoLong", " 789 ");
properties.setProperty("demoDouble", " 1.5 ");
properties.setProperty("demoFloat", " 2.5 ");
properties.setProperty("demoName", " TestDemo ");

MixAll.properties2Object(properties, demoConfig);

assertThat(demoConfig.getDemoLength()).isEqualTo(456);
assertThat(demoConfig.getDemoWidth()).isEqualTo(123);
assertThat(demoConfig.isDemoOK()).isTrue();
assertThat(demoConfig.getDemoLong()).isEqualTo(789);
assertThat(demoConfig.getDemoDouble()).isEqualTo(1.5);
assertThat(demoConfig.getDemoFloat()).isEqualTo(2.5f);
assertThat(demoConfig.getDemoName()).isEqualTo("TestDemo");
}

@Test
public void testProperties2String() {
DemoSubConfig demoConfig = new DemoSubConfig();
Expand Down Expand Up @@ -155,6 +178,9 @@ static class DemoConfig {
private int demoWidth = 0;
private int demoLength = 0;
private boolean demoOK = false;
private long demoLong = 0;
private double demoDouble = 0;
private float demoFloat = 0;
private String demoName = "haha";

int getDemoWidth() {
Expand All @@ -181,6 +207,30 @@ public void setDemoOK(boolean demoOK) {
this.demoOK = demoOK;
}

public long getDemoLong() {
return demoLong;
}

public void setDemoLong(long demoLong) {
this.demoLong = demoLong;
}

public double getDemoDouble() {
return demoDouble;
}

public void setDemoDouble(double demoDouble) {
this.demoDouble = demoDouble;
}

public float getDemoFloat() {
return demoFloat;
}

public void setDemoFloat(float demoFloat) {
this.demoFloat = demoFloat;
}

public String getDemoName() {
return demoName;
}
Expand Down