提交 2db3fcb4 authored 作者: 陈世营's avatar 陈世营

【修改】 leaf 配置修改

上级 1a0ef56e
package com.loit.component.keygen.leaf; package com.loit.component.keygen.leaf;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
...@@ -10,6 +11,7 @@ import lombok.Getter; ...@@ -10,6 +11,7 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
...@@ -19,7 +21,7 @@ import java.util.concurrent.SynchronousQueue; ...@@ -19,7 +21,7 @@ import java.util.concurrent.SynchronousQueue;
* Key generator implemented by leaf segment algorithms. * Key generator implemented by leaf segment algorithms.
* *
*/ */
public final class LeafSegmentLeafKeyGenerator implements LeafKeyGenerator { public final class LeafSegmentKeyGenerator implements LeafKeyGenerator {
private static final String DEFAULT_NAMESPACE = "leaf_segment"; private static final String DEFAULT_NAMESPACE = "leaf_segment";
...@@ -47,7 +49,7 @@ public final class LeafSegmentLeafKeyGenerator implements LeafKeyGenerator { ...@@ -47,7 +49,7 @@ public final class LeafSegmentLeafKeyGenerator implements LeafKeyGenerator {
@Setter @Setter
private Properties properties = new Properties(); private Properties properties = new Properties();
public LeafSegmentLeafKeyGenerator() { public LeafSegmentKeyGenerator() {
incrementCacheIdExecutor = Executors.newSingleThreadExecutor(); incrementCacheIdExecutor = Executors.newSingleThreadExecutor();
cacheIdQueue = new SynchronousQueue<>(); cacheIdQueue = new SynchronousQueue<>();
} }
...@@ -163,35 +165,35 @@ public final class LeafSegmentLeafKeyGenerator implements LeafKeyGenerator { ...@@ -163,35 +165,35 @@ public final class LeafSegmentLeafKeyGenerator implements LeafKeyGenerator {
} }
private long getStep() { private long getStep() {
long result = Long.parseLong(properties.getProperty("step", DEFAULT_STEP)); long result = Long.parseLong(properties.getProperty("leaf.segment.step", DEFAULT_STEP));
Preconditions.checkArgument(result > 0L && result < Long.MAX_VALUE); Preconditions.checkArgument(result > 0L && result < Long.MAX_VALUE);
return result; return result;
} }
private long getInitialValue() { private long getInitialValue() {
long result = Long.parseLong(properties.getProperty("initialValue", DEFAULT_INITIAL_VALUE)); long result = Long.parseLong(properties.getProperty("leaf.segment.id.initial.value", DEFAULT_INITIAL_VALUE));
Preconditions.checkArgument(result >= 0L && result < Long.MAX_VALUE); Preconditions.checkArgument(result >= 0L && result < Long.MAX_VALUE);
return result; return result;
} }
private String getLeafKey() { private String getLeafKey() {
String leafKey = properties.getProperty("leafKey"); String leafKey = properties.getProperty("leaf.key");
Preconditions.checkArgument(!Strings.isNullOrEmpty(leafKey)); Preconditions.checkArgument(!Strings.isNullOrEmpty(leafKey));
Preconditions.checkArgument(leafKey.matches(REGULAR_PATTERN)); Preconditions.checkArgument(leafKey.matches(REGULAR_PATTERN));
return SLANTING_BAR + leafKey; return SLANTING_BAR + leafKey;
} }
private String getServerList() { private String getServerList() {
String result = properties.getProperty("serverList"); String result = properties.getProperty("server.list");
Preconditions.checkArgument(!Strings.isNullOrEmpty(result)); Preconditions.checkArgument(!Strings.isNullOrEmpty(result));
return result; return result;
} }
private String getDigest() { private String getDigest() {
return properties.getProperty("digest"); return properties.getProperty("registry.center.digest");
} }
private String getRegistryCenterType() { private String getRegistryCenterType() {
return properties.getProperty("registryCenterType", DEFAULT_REGISTRY_CENTER); return properties.getProperty("registry.center.type", DEFAULT_REGISTRY_CENTER);
} }
} }
...@@ -13,15 +13,15 @@ import static org.hamcrest.CoreMatchers.is; ...@@ -13,15 +13,15 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
@FixMethodOrder(value = MethodSorters.NAME_ASCENDING) @FixMethodOrder(value = MethodSorters.NAME_ASCENDING)
public final class LeafSegmentLeafKeyGeneratorTest { public final class LeafSegmentKeyGeneratorTest {
private final LeafSegmentLeafKeyGenerator leafSegmentKeyGenerator = new LeafSegmentLeafKeyGenerator(); private final LeafSegmentKeyGenerator leafSegmentKeyGenerator = new LeafSegmentKeyGenerator();
@Test @Test
public void assertGetProperties() { public void assertGetProperties() {
assertThat(leafSegmentKeyGenerator.getProperties().entrySet().size(), is(0)); assertThat(leafSegmentKeyGenerator.getProperties().entrySet().size(), is(0));
} }
@Test @Test
public void assertSetProperties() { public void assertSetProperties() {
Properties properties = new Properties(); Properties properties = new Properties();
...@@ -29,15 +29,15 @@ public final class LeafSegmentLeafKeyGeneratorTest { ...@@ -29,15 +29,15 @@ public final class LeafSegmentLeafKeyGeneratorTest {
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
assertThat(leafSegmentKeyGenerator.getProperties().get("key1"), is((Object) "value1")); assertThat(leafSegmentKeyGenerator.getProperties().get("key1"), is((Object) "value1"));
} }
@Test @Test
public void assertGenerateKeyWithSingleThread() { public void assertGenerateKeyWithSingleThread() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181"); properties.setProperty("server.list", "127.0.0.1:2181");
properties.setProperty("initialValue", "100001"); properties.setProperty("leaf.segment.id.initial.value", "100001");
properties.setProperty("step", "5"); properties.setProperty("leaf.segment.step", "5");
properties.setProperty("leafKey", "test_table_1"); properties.setProperty("leaf.key", "test_table_1");
properties.setProperty("registryCenterType", "zookeeper"); properties.setProperty("registry.center.type", "zookeeper");
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
List<Comparable<?>> expected = Arrays.<Comparable<?>>asList(100001L, 100002L, 100003L, 100004L, 100005L, 100006L, 100007L, 100008L, 100009L, 100010L); List<Comparable<?>> expected = Arrays.<Comparable<?>>asList(100001L, 100002L, 100003L, 100004L, 100005L, 100006L, 100007L, 100008L, 100009L, 100010L);
List<Comparable<?>> actual = new ArrayList<>(); List<Comparable<?>> actual = new ArrayList<>();
...@@ -46,15 +46,15 @@ public final class LeafSegmentLeafKeyGeneratorTest { ...@@ -46,15 +46,15 @@ public final class LeafSegmentLeafKeyGeneratorTest {
} }
assertThat(actual, is(expected)); assertThat(actual, is(expected));
} }
@Test @Test
public void assertGenerateKeyWithFirstSpecialStep() { public void assertGenerateKeyWithFirstSpecialStep() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181"); properties.setProperty("server.list", "127.0.0.1:2181");
properties.setProperty("initialValue", "100001"); properties.setProperty("leaf.segment.id.initial.value", "100001");
properties.setProperty("step", "3"); properties.setProperty("leaf.segment.step", "3");
properties.setProperty("leafKey", "test_table_6"); properties.setProperty("leaf.key", "test_table_6");
properties.setProperty("registryCenterType", "zookeeper"); properties.setProperty("registry.center.type", "zookeeper");
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
List<Comparable<?>> expected = Arrays.<Comparable<?>>asList(100001L, 100002L, 100003L, 100004L, 100005L, 100006L, 100007L, 100008L, 100009L, 100010L); List<Comparable<?>> expected = Arrays.<Comparable<?>>asList(100001L, 100002L, 100003L, 100004L, 100005L, 100006L, 100007L, 100008L, 100009L, 100010L);
List<Comparable<?>> actual = new ArrayList<>(); List<Comparable<?>> actual = new ArrayList<>();
...@@ -63,15 +63,15 @@ public final class LeafSegmentLeafKeyGeneratorTest { ...@@ -63,15 +63,15 @@ public final class LeafSegmentLeafKeyGeneratorTest {
} }
assertThat(actual, is(expected)); assertThat(actual, is(expected));
} }
@Test @Test
public void assertGenerateKeyWithSecondSpecialStep() { public void assertGenerateKeyWithSecondSpecialStep() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181"); properties.setProperty("server.list", "127.0.0.1:2181");
properties.setProperty("initialValue", "100001"); properties.setProperty("leaf.segment.id.initial.value", "100001");
properties.setProperty("step", "7"); properties.setProperty("leaf.segment.step", "7");
properties.setProperty("leafKey", "test_table_7"); properties.setProperty("leaf.key", "test_table_7");
properties.setProperty("registryCenterType", "zookeeper"); properties.setProperty("registry.center.type", "zookeeper");
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
List<Comparable<?>> expected = Arrays.<Comparable<?>>asList(100001L, 100002L, 100003L, 100004L, 100005L, 100006L, 100007L, 100008L, 100009L, 100010L); List<Comparable<?>> expected = Arrays.<Comparable<?>>asList(100001L, 100002L, 100003L, 100004L, 100005L, 100006L, 100007L, 100008L, 100009L, 100010L);
List<Comparable<?>> actual = new ArrayList<>(); List<Comparable<?>> actual = new ArrayList<>();
...@@ -80,17 +80,17 @@ public final class LeafSegmentLeafKeyGeneratorTest { ...@@ -80,17 +80,17 @@ public final class LeafSegmentLeafKeyGeneratorTest {
} }
assertThat(actual, is(expected)); assertThat(actual, is(expected));
} }
@Test @Test
public void assertGenerateKeyWithMultipleThreads() throws Exception { public void assertGenerateKeyWithMultipleThreads() throws Exception {
int threadNumber = 2; int threadNumber = 2;
ExecutorService executor = Executors.newFixedThreadPool(threadNumber); ExecutorService executor = Executors.newFixedThreadPool(threadNumber);
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181"); properties.setProperty("server.list", "127.0.0.1:2181");
properties.setProperty("initialValue", "100001"); properties.setProperty("leaf.segment.id.initial.value", "100001");
properties.setProperty("step", "3"); properties.setProperty("leaf.segment.step", "3");
properties.setProperty("leafKey", "test_table_2"); properties.setProperty("leaf.key", "test_table_2");
properties.setProperty("registryCenterType", "zookeeper"); properties.setProperty("registry.center.type", "zookeeper");
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
Set<Comparable<?>> actual = new HashSet<>(); Set<Comparable<?>> actual = new HashSet<>();
int taskNumber = threadNumber * 2; int taskNumber = threadNumber * 2;
...@@ -105,18 +105,18 @@ public final class LeafSegmentLeafKeyGeneratorTest { ...@@ -105,18 +105,18 @@ public final class LeafSegmentLeafKeyGeneratorTest {
} }
assertThat(actual.size(), is(taskNumber)); assertThat(actual.size(), is(taskNumber));
} }
@Test @Test
public void assertGenerateKeyWithDigest() throws Exception { public void assertGenerateKeyWithDigest() throws Exception {
int threadNumber = 2; int threadNumber = 2;
ExecutorService executor = Executors.newFixedThreadPool(threadNumber); ExecutorService executor = Executors.newFixedThreadPool(threadNumber);
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181"); properties.setProperty("server.list", "127.0.0.1:2181");
properties.setProperty("initialValue", "100001"); properties.setProperty("leaf.segment.id.initial.value", "100001");
properties.setProperty("step", "3"); properties.setProperty("leaf.segment.step", "3");
properties.setProperty("digest", "name:123456"); properties.setProperty("registry.center.digest", "name:123456");
properties.setProperty("leafKey", "test_table_3"); properties.setProperty("leaf.key", "test_table_3");
properties.setProperty("registryCenterType", "zookeeper"); properties.setProperty("registry.center.type", "zookeeper");
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
Set<Comparable<?>> actual = new HashSet<>(); Set<Comparable<?>> actual = new HashSet<>();
int taskNumber = threadNumber * 2; int taskNumber = threadNumber * 2;
...@@ -131,16 +131,16 @@ public final class LeafSegmentLeafKeyGeneratorTest { ...@@ -131,16 +131,16 @@ public final class LeafSegmentLeafKeyGeneratorTest {
} }
assertThat(actual.size(), is(taskNumber)); assertThat(actual.size(), is(taskNumber));
} }
@Test @Test
public void assertGenerateKeyWithDefaultStep() throws Exception { public void assertGenerateKeyWithDefaultStep() throws Exception {
int threadNumber = 2; int threadNumber = 2;
ExecutorService executor = Executors.newFixedThreadPool(threadNumber); ExecutorService executor = Executors.newFixedThreadPool(threadNumber);
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181"); properties.setProperty("server.list", "127.0.0.1:2181");
properties.setProperty("initialValue", "100001"); properties.setProperty("leaf.segment.id.initial.value", "100001");
properties.setProperty("leafKey", "test_table_4"); properties.setProperty("leaf.key", "test_table_4");
properties.setProperty("registryCenterType", "zookeeper"); properties.setProperty("registry.center.type", "zookeeper");
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
Set<Comparable<?>> actual = new HashSet<>(); Set<Comparable<?>> actual = new HashSet<>();
int taskNumber = threadNumber * 2; int taskNumber = threadNumber * 2;
...@@ -155,16 +155,16 @@ public final class LeafSegmentLeafKeyGeneratorTest { ...@@ -155,16 +155,16 @@ public final class LeafSegmentLeafKeyGeneratorTest {
} }
assertThat(actual.size(), is(taskNumber)); assertThat(actual.size(), is(taskNumber));
} }
@Test @Test
public void assertGenerateKeyWithDefaultInitialValue() throws Exception { public void assertGenerateKeyWithDefaultInitialValue() throws Exception {
int threadNumber = 2; int threadNumber = 2;
ExecutorService executor = Executors.newFixedThreadPool(threadNumber); ExecutorService executor = Executors.newFixedThreadPool(threadNumber);
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181"); properties.setProperty("server.list", "127.0.0.1:2181");
properties.setProperty("step", "3"); properties.setProperty("leaf.segment.step", "3");
properties.setProperty("leafKey", "test_table_5"); properties.setProperty("leaf.key", "test_table_5");
properties.setProperty("registryCenterType", "zookeeper"); properties.setProperty("registry.center.type", "zookeeper");
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
int taskNumber = threadNumber * 2; int taskNumber = threadNumber * 2;
Set<Comparable<?>> actual = new HashSet<>(); Set<Comparable<?>> actual = new HashSet<>();
...@@ -179,133 +179,133 @@ public final class LeafSegmentLeafKeyGeneratorTest { ...@@ -179,133 +179,133 @@ public final class LeafSegmentLeafKeyGeneratorTest {
} }
assertThat(actual.size(), is(taskNumber)); assertThat(actual.size(), is(taskNumber));
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void assertSetStepFailureWhenNegative() { public void assertSetStepFailureWhenNegative() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181"); properties.setProperty("server.list", "127.0.0.1:2181");
properties.setProperty("step", String.valueOf(-1L)); properties.setProperty("leaf.segment.step", String.valueOf(-1L));
properties.setProperty("initialValue", "100001"); properties.setProperty("leaf.segment.id.initial.value", "100001");
properties.setProperty("leafKey", "test_table_9"); properties.setProperty("leaf.key", "test_table_9");
properties.setProperty("registryCenterType", "zookeeper"); properties.setProperty("registry.center.type", "zookeeper");
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
leafSegmentKeyGenerator.generateKey(); leafSegmentKeyGenerator.generateKey();
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void assertSetStepFailureWhenZero() { public void assertSetStepFailureWhenZero() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181"); properties.setProperty("server.list", "127.0.0.1:2181");
properties.setProperty("step", String.valueOf(0L)); properties.setProperty("leaf.segment.step", String.valueOf(0L));
properties.setProperty("initialValue", "100001"); properties.setProperty("leaf.segment.id.initial.value", "100001");
properties.setProperty("leafKey", "test_table_10"); properties.setProperty("leaf.key", "test_table_10");
properties.setProperty("registryCenterType", "zookeeper"); properties.setProperty("registry.center.type", "zookeeper");
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
leafSegmentKeyGenerator.generateKey(); leafSegmentKeyGenerator.generateKey();
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void assertSetStepFailureWhenTooMuch() { public void assertSetStepFailureWhenTooMuch() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181"); properties.setProperty("server.list", "127.0.0.1:2181");
properties.setProperty("step", String.valueOf(Long.MAX_VALUE)); properties.setProperty("leaf.segment.step", String.valueOf(Long.MAX_VALUE));
properties.setProperty("initialValue", "100001"); properties.setProperty("leaf.segment.id.initial.value", "100001");
properties.setProperty("leafKey", "test_table_11"); properties.setProperty("leaf.key", "test_table_11");
properties.setProperty("registryCenterType", "zookeeper"); properties.setProperty("registry.center.type", "zookeeper");
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
leafSegmentKeyGenerator.generateKey(); leafSegmentKeyGenerator.generateKey();
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void assertSetInitialValueFailureWhenNegative() { public void assertSetInitialValueFailureWhenNegative() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181"); properties.setProperty("server.list", "127.0.0.1:2181");
properties.setProperty("step", "3"); properties.setProperty("leaf.segment.step", "3");
properties.setProperty("initialValue", String.valueOf(-1L)); properties.setProperty("leaf.segment.id.initial.value", String.valueOf(-1L));
properties.setProperty("leafKey", "test_table_12"); properties.setProperty("leaf.key", "test_table_12");
properties.setProperty("registryCenterType", "zookeeper"); properties.setProperty("registry.center.type", "zookeeper");
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
leafSegmentKeyGenerator.generateKey(); leafSegmentKeyGenerator.generateKey();
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void assertSetInitialValueFailureWhenTooMuch() { public void assertSetInitialValueFailureWhenTooMuch() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181"); properties.setProperty("server.list", "127.0.0.1:2181");
properties.setProperty("step", "3"); properties.setProperty("leaf.segment.step", "3");
properties.setProperty("initialValue", String.valueOf(Long.MAX_VALUE)); properties.setProperty("leaf.segment.id.initial.value", String.valueOf(Long.MAX_VALUE));
properties.setProperty("leafKey", "test_table_13"); properties.setProperty("leaf.key", "test_table_13");
properties.setProperty("registryCenterType", "zookeeper"); properties.setProperty("registry.center.type", "zookeeper");
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
leafSegmentKeyGenerator.generateKey(); leafSegmentKeyGenerator.generateKey();
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void assertSetServerListFailureWhenNull() { public void assertSetServerListFailureWhenNull() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("step", "3"); properties.setProperty("leaf.segment.step", "3");
properties.setProperty("initialValue", "100001"); properties.setProperty("leaf.segment.id.initial.value", "100001");
properties.setProperty("leafKey", "test_table_14"); properties.setProperty("leaf.key", "test_table_14");
properties.setProperty("registryCenterType", "zookeeper"); properties.setProperty("registry.center.type", "zookeeper");
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
leafSegmentKeyGenerator.generateKey(); leafSegmentKeyGenerator.generateKey();
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void assertSetServerListFailureWhenArgumentEmpty() { public void assertSetServerListFailureWhenArgumentEmpty() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("serverList", ""); properties.setProperty("server.list", "");
properties.setProperty("step", "3"); properties.setProperty("leaf.segment.step", "3");
properties.setProperty("initialValue", "100001"); properties.setProperty("leaf.segment.id.initial.value", "100001");
properties.setProperty("leafKey", "test_table_15"); properties.setProperty("leaf.key", "test_table_15");
properties.setProperty("registryCenterType", "zookeeper"); properties.setProperty("registry.center.type", "zookeeper");
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
leafSegmentKeyGenerator.generateKey(); leafSegmentKeyGenerator.generateKey();
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void assertSetLeafKeyFailureWhenArgumentIllegal() { public void assertSetLeafKeyFailureWhenArgumentIllegal() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181"); properties.setProperty("server.list", "127.0.0.1:2181");
properties.setProperty("step", "3"); properties.setProperty("leaf.segment.step", "3");
properties.setProperty("initialValue", "100001"); properties.setProperty("leaf.segment.id.initial.value", "100001");
properties.setProperty("leafKey", "/test_table_16"); properties.setProperty("leaf.key", "/test_table_16");
properties.setProperty("registryCenterType", "zookeeper"); properties.setProperty("registry.center.type", "zookeeper");
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
leafSegmentKeyGenerator.generateKey(); leafSegmentKeyGenerator.generateKey();
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void assertSetLeafKeyFailureWhenArgumentEmpty() { public void assertSetLeafKeyFailureWhenArgumentEmpty() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181"); properties.setProperty("server.list", "127.0.0.1:2181");
properties.setProperty("step", "3"); properties.setProperty("leaf.segment.step", "3");
properties.setProperty("initialValue", "100001"); properties.setProperty("leaf.segment.id.initial.value", "100001");
properties.setProperty("leafKey", ""); properties.setProperty("leaf.key", "");
properties.setProperty("registryCenterType", "zookeeper"); properties.setProperty("registry.center.type", "zookeeper");
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
leafSegmentKeyGenerator.generateKey(); leafSegmentKeyGenerator.generateKey();
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void assertSetLeafKeyFailureWhenNull() { public void assertSetLeafKeyFailureWhenNull() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181"); properties.setProperty("server.list", "127.0.0.1:2181");
properties.setProperty("step", "3"); properties.setProperty("leaf.segment.step", "3");
properties.setProperty("initialValue", "100001"); properties.setProperty("leaf.segment.id.initial.value", "100001");
properties.setProperty("registryCenterType", "zookeeper"); properties.setProperty("registry.center.type", "zookeeper");
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
leafSegmentKeyGenerator.generateKey(); leafSegmentKeyGenerator.generateKey();
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void assertSetRegistryCenterTypeFailureWhenWrongType() { public void assertSetRegistryCenterTypeFailureWhenWrongType() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("serverList", "127.0.0.1:2181"); properties.setProperty("server.list", "127.0.0.1:2181");
properties.setProperty("step", "3"); properties.setProperty("leaf.segment.step", "3");
properties.setProperty("initialValue", "100001"); properties.setProperty("leaf.segment.id.initial.value", "100001");
properties.setProperty("leafKey", "/test_table_17"); properties.setProperty("leaf.key", "/test_table_17");
properties.setProperty("registryCenterType", "zookeeper"); properties.setProperty("registry.center.type", "zookeeper");
leafSegmentKeyGenerator.setProperties(properties); leafSegmentKeyGenerator.setProperties(properties);
leafSegmentKeyGenerator.generateKey(); leafSegmentKeyGenerator.generateKey();
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论