Skip to content

Commit d9724c3

Browse files
committed
Update jetcd, dynamic-config
1 parent 7d6e131 commit d9724c3

13 files changed

Lines changed: 118 additions & 41 deletions

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
</modules>
4242

4343
<properties>
44-
<dynamicconfig.version>3.1-SNAPSHOT</dynamicconfig.version>
45-
<jetcd-version>0.4.1</jetcd-version>
44+
<dynamicconfig.version>4.0-beta2</dynamicconfig.version>
45+
<jetcd-version>0.6.1</jetcd-version>
4646
<slf4j.version>1.7.32</slf4j.version>
4747
<javax.annotation.version>1.3.2</javax.annotation.version>
4848

uniqueid-etcd/src/main/java/org/lable/oss/uniqueid/etcd/EtcdHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
import io.etcd.jetcd.ByteSequence;
1919
import io.etcd.jetcd.Client;
20-
import io.etcd.jetcd.CloseableClient;
2120
import io.etcd.jetcd.kv.GetResponse;
2221
import io.etcd.jetcd.lease.LeaseKeepAliveResponse;
22+
import io.etcd.jetcd.support.CloseableClient;
2323
import io.grpc.stub.StreamObserver;
2424

2525
import java.nio.charset.StandardCharsets;

uniqueid-etcd/src/main/java/org/lable/oss/uniqueid/etcd/ResourceClaim.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
*/
1616
package org.lable.oss.uniqueid.etcd;
1717

18-
import io.etcd.jetcd.*;
18+
import io.etcd.jetcd.ByteSequence;
19+
import io.etcd.jetcd.Client;
20+
import io.etcd.jetcd.KeyValue;
21+
import io.etcd.jetcd.Watch;
1922
import io.etcd.jetcd.kv.GetResponse;
2023
import io.etcd.jetcd.kv.TxnResponse;
2124
import io.etcd.jetcd.lease.LeaseGrantResponse;
@@ -26,6 +29,7 @@
2629
import io.etcd.jetcd.options.GetOption;
2730
import io.etcd.jetcd.options.PutOption;
2831
import io.etcd.jetcd.options.WatchOption;
32+
import io.etcd.jetcd.support.CloseableClient;
2933
import io.etcd.jetcd.watch.WatchEvent;
3034
import org.slf4j.Logger;
3135
import org.slf4j.LoggerFactory;

uniqueid-etcd/src/test/java/org/lable/oss/uniqueid/etcd/AcquisitionTimeoutIT.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
import io.etcd.jetcd.ByteSequence;
1919
import io.etcd.jetcd.Client;
20-
import io.etcd.jetcd.CloseableClient;
21-
import io.etcd.jetcd.launcher.junit4.EtcdClusterResource;
20+
import io.etcd.jetcd.support.CloseableClient;
2221
import org.junit.*;
2322
import org.junit.rules.ExpectedException;
2423

@@ -31,15 +30,15 @@
3130
import java.util.concurrent.ExecutionException;
3231

3332
import static org.hamcrest.CoreMatchers.is;
33+
import static org.hamcrest.MatcherAssert.assertThat;
3434
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
3535
import static org.hamcrest.Matchers.lessThan;
3636
import static org.hamcrest.core.CombinableMatcher.both;
37-
import static org.hamcrest.MatcherAssert.assertThat;
3837
import static org.lable.oss.uniqueid.etcd.ResourceClaim.LOCK_NAME;
3938

4039
public class AcquisitionTimeoutIT {
4140
@ClassRule
42-
public static final EtcdClusterResource etcd = new EtcdClusterResource("test-etcd", 1);
41+
public static final EtcdTestCluster etcd = new EtcdTestCluster("test-etcd", 1);
4342

4443
@Rule
4544
public ExpectedException thrown = ExpectedException.none();

uniqueid-etcd/src/test/java/org/lable/oss/uniqueid/etcd/ClusterIDIT.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import io.etcd.jetcd.ByteSequence;
1919
import io.etcd.jetcd.Client;
20-
import io.etcd.jetcd.launcher.junit4.EtcdClusterResource;
2120
import org.junit.Rule;
2221
import org.junit.Test;
2322

@@ -26,12 +25,12 @@
2625
import java.util.List;
2726
import java.util.concurrent.ExecutionException;
2827

29-
import static org.hamcrest.Matchers.contains;
3028
import static org.hamcrest.MatcherAssert.assertThat;
29+
import static org.hamcrest.Matchers.contains;
3130

3231
public class ClusterIDIT {
3332
@Rule
34-
public final EtcdClusterResource etcd = new EtcdClusterResource("test-etcd", 1);
33+
public final EtcdTestCluster etcd = new EtcdTestCluster("test-etcd", 1);
3534

3635
@Test
3736
public void defaultTest() throws IOException {

uniqueid-etcd/src/test/java/org/lable/oss/uniqueid/etcd/EtcdHelperIT.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,19 @@
1616
package org.lable.oss.uniqueid.etcd;
1717

1818
import io.etcd.jetcd.Client;
19-
import io.etcd.jetcd.launcher.junit4.EtcdClusterResource;
2019
import org.junit.Rule;
2120
import org.junit.Test;
2221

2322
import java.util.concurrent.ExecutionException;
2423

2524
import static com.github.npathai.hamcrestopt.OptionalMatchers.hasValue;
2625
import static com.github.npathai.hamcrestopt.OptionalMatchers.isEmpty;
27-
import static org.hamcrest.CoreMatchers.is;
2826
import static org.hamcrest.MatcherAssert.assertThat;
2927
import static org.lable.oss.uniqueid.etcd.EtcdHelper.*;
3028

3129
public class EtcdHelperIT {
3230
@Rule
33-
public final EtcdClusterResource etcd = new EtcdClusterResource("test-etcd", 1);
31+
public final EtcdTestCluster etcd = new EtcdTestCluster("test-etcd", 1);
3432

3533
@Test
3634
public void test() throws ExecutionException, InterruptedException {
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright © 2014 Lable (info@lable.nl)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* Copyright © 2015 Lable (info@lable.nl)
19+
*
20+
* Licensed under the Apache License, Version 2.0 (the "License");
21+
* you may not use this file except in compliance with the License.
22+
* You may obtain a copy of the License at
23+
*
24+
* http://www.apache.org/licenses/LICENSE-2.0
25+
*
26+
* Unless required by applicable law or agreed to in writing, software
27+
* distributed under the License is distributed on an "AS IS" BASIS,
28+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29+
* See the License for the specific language governing permissions and
30+
* limitations under the License.
31+
*/
32+
package org.lable.oss.uniqueid.etcd;
33+
34+
import io.etcd.jetcd.launcher.Etcd;
35+
import io.etcd.jetcd.launcher.EtcdCluster;
36+
import org.junit.rules.TestRule;
37+
import org.junit.runner.Description;
38+
import org.junit.runners.model.Statement;
39+
40+
import java.net.URI;
41+
import java.util.List;
42+
43+
/**
44+
* The jetcd library dropped support for JUnit4, so we wrap the cluster ourselves.
45+
*/
46+
public class EtcdTestCluster implements TestRule {
47+
48+
private final String clusterName;
49+
private final int nodes;
50+
private final boolean ssl;
51+
private EtcdCluster cluster;
52+
53+
public EtcdTestCluster(String clusterName, int nodes) {
54+
this(clusterName, nodes, false);
55+
}
56+
57+
public EtcdTestCluster(String clusterName, int nodes, boolean ssl) {
58+
this.clusterName = clusterName;
59+
this.nodes = nodes;
60+
this.ssl = ssl;
61+
}
62+
63+
@Override
64+
public Statement apply(Statement base, Description description) {
65+
return new Statement() {
66+
@Override
67+
public void evaluate() throws Throwable {
68+
cluster = Etcd.builder()
69+
.withClusterName(clusterName)
70+
.withNodes(nodes)
71+
.withSsl(ssl)
72+
.build();
73+
74+
cluster.start();
75+
try {
76+
base.evaluate();
77+
} finally {
78+
cluster.close();
79+
cluster = null;
80+
}
81+
}
82+
};
83+
}
84+
85+
public List<URI> getClientEndpoints() {
86+
return cluster.clientEndpoints();
87+
}
88+
}

uniqueid-etcd/src/test/java/org/lable/oss/uniqueid/etcd/ExpiringResourceClaimIT.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import io.etcd.jetcd.ByteSequence;
1919
import io.etcd.jetcd.Client;
20-
import io.etcd.jetcd.launcher.junit4.EtcdClusterResource;
2120
import org.junit.Before;
2221
import org.junit.Rule;
2322
import org.junit.Test;
@@ -31,17 +30,17 @@
3130
import java.util.concurrent.TimeUnit;
3231

3332
import static com.github.npathai.hamcrestopt.OptionalMatchers.isEmpty;
34-
import static org.hamcrest.CoreMatchers.*;
33+
import static org.hamcrest.CoreMatchers.is;
34+
import static org.hamcrest.MatcherAssert.assertThat;
3535
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
3636
import static org.hamcrest.Matchers.lessThan;
3737
import static org.hamcrest.core.CombinableMatcher.both;
38-
import static org.hamcrest.MatcherAssert.assertThat;
3938
import static org.lable.oss.uniqueid.etcd.ResourceClaim.POOL_PREFIX;
4039
import static org.lable.oss.uniqueid.etcd.ResourceClaim.resourceKey;
4140

4241
public class ExpiringResourceClaimIT {
4342
@Rule
44-
public final EtcdClusterResource etcd = new EtcdClusterResource("test-etcd", 1);
43+
public final EtcdTestCluster etcd = new EtcdTestCluster("test-etcd", 1);
4544

4645
@Rule
4746
public ExpectedException thrown = ExpectedException.none();

uniqueid-etcd/src/test/java/org/lable/oss/uniqueid/etcd/HighGeneratorCountIT.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,24 @@
1717

1818
import io.etcd.jetcd.ByteSequence;
1919
import io.etcd.jetcd.Client;
20-
import io.etcd.jetcd.launcher.junit4.EtcdClusterResource;
21-
import org.apache.commons.codec.binary.Hex;
2220
import org.junit.BeforeClass;
2321
import org.junit.ClassRule;
2422
import org.junit.Test;
25-
import org.lable.oss.uniqueid.ByteArray;
26-
import org.lable.oss.uniqueid.GeneratorException;
2723
import org.lable.oss.uniqueid.IDGenerator;
2824
import org.lable.oss.uniqueid.bytes.Blueprint;
2925
import org.lable.oss.uniqueid.bytes.IDBuilder;
3026
import org.lable.oss.uniqueid.bytes.Mode;
3127

32-
import java.io.IOException;
3328
import java.nio.charset.StandardCharsets;
34-
import java.util.*;
35-
import java.util.concurrent.*;
36-
import java.util.concurrent.atomic.AtomicLong;
29+
import java.util.concurrent.ExecutionException;
3730

3831
import static org.hamcrest.CoreMatchers.is;
3932
import static org.junit.Assert.assertThat;
40-
import static org.junit.Assert.fail;
4133
import static org.lable.oss.uniqueid.etcd.SynchronizedUniqueIDGeneratorFactory.generatorFor;
4234

4335
public class HighGeneratorCountIT {
4436
@ClassRule
45-
public static final EtcdClusterResource etcd = new EtcdClusterResource("test-etcd", 1);
37+
public static final EtcdTestCluster etcd = new EtcdTestCluster("test-etcd", 1);
4638

4739
final static int CLUSTER_ID_A = 4;
4840
final static int CLUSTER_ID_B = 5;

uniqueid-etcd/src/test/java/org/lable/oss/uniqueid/etcd/MultipleClusterIdsIT.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import io.etcd.jetcd.ByteSequence;
1919
import io.etcd.jetcd.Client;
20-
import io.etcd.jetcd.launcher.junit4.EtcdClusterResource;
2120
import org.junit.*;
2221
import org.junit.rules.ExpectedException;
2322
import org.lable.oss.uniqueid.ByteArray;
@@ -29,8 +28,13 @@
2928

3029
import java.io.IOException;
3130
import java.nio.charset.StandardCharsets;
32-
import java.util.*;
33-
import java.util.concurrent.*;
31+
import java.util.HashMap;
32+
import java.util.HashSet;
33+
import java.util.Map;
34+
import java.util.Set;
35+
import java.util.concurrent.ConcurrentLinkedDeque;
36+
import java.util.concurrent.CountDownLatch;
37+
import java.util.concurrent.ExecutionException;
3438

3539
import static org.hamcrest.CoreMatchers.is;
3640
import static org.hamcrest.MatcherAssert.assertThat;
@@ -39,7 +43,7 @@
3943

4044
public class MultipleClusterIdsIT {
4145
@ClassRule
42-
public static final EtcdClusterResource etcd = new EtcdClusterResource("test-etcd", 1);
46+
public static final EtcdTestCluster etcd = new EtcdTestCluster("test-etcd", 1);
4347

4448
@Rule
4549
public ExpectedException thrown = ExpectedException.none();

0 commit comments

Comments
 (0)