Skip to content

Commit

Permalink
Clean up REST API tests and ensure primitive protocols can be properl…
Browse files Browse the repository at this point in the history
…y passed via the REST API.
  • Loading branch information
kuujo committed Apr 27, 2018
1 parent 8e401a1 commit 869db78
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 28 deletions.
Expand Up @@ -34,7 +34,7 @@ public AtomicCounterProxyBuilder(String name, AtomicCounterConfig config, Primit
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public CompletableFuture<AtomicCounter> buildAsync() { public CompletableFuture<AtomicCounter> buildAsync() {
PrimitiveProxy proxy = protocol.newProxy( PrimitiveProxy proxy = protocol().newProxy(
name(), name(),
primitiveType(), primitiveType(),
managementService.getPartitionService()); managementService.getPartitionService());
Expand Down
Expand Up @@ -35,16 +35,16 @@ public LeaderElectionProxyBuilder(String name, LeaderElectionConfig config, Prim
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public CompletableFuture<LeaderElection<T>> buildAsync() { public CompletableFuture<LeaderElection<T>> buildAsync() {
PrimitiveProxy proxy = protocol.newProxy( PrimitiveProxy proxy = protocol().newProxy(
name(), name(),
primitiveType(), primitiveType(),
managementService.getPartitionService()); managementService.getPartitionService());
return new LeaderElectionProxy(proxy, managementService.getPrimitiveRegistry()) return new LeaderElectionProxy(proxy, managementService.getPrimitiveRegistry())
.connect() .connect()
.thenApply(elector -> { .thenApply(election -> {
Serializer serializer = serializer(); Serializer serializer = serializer();
return new TranscodingAsyncLeaderElection<T, byte[]>( return new TranscodingAsyncLeaderElection<T, byte[]>(
elector, election,
key -> serializer.encode(key), key -> serializer.encode(key),
bytes -> serializer.decode(bytes)) bytes -> serializer.decode(bytes))
.sync(); .sync();
Expand Down
Expand Up @@ -35,7 +35,7 @@ public LeaderElectorProxyBuilder(String name, LeaderElectorConfig config, Primit
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public CompletableFuture<LeaderElector<T>> buildAsync() { public CompletableFuture<LeaderElector<T>> buildAsync() {
PrimitiveProxy proxy = protocol.newProxy( PrimitiveProxy proxy = protocol().newProxy(
name(), name(),
primitiveType(), primitiveType(),
managementService.getPartitionService()); managementService.getPartitionService());
Expand Down
Expand Up @@ -35,7 +35,7 @@ public DelegatingAtomicIdGeneratorBuilder(String name, AtomicIdGeneratorConfig c
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public CompletableFuture<AtomicIdGenerator> buildAsync() { public CompletableFuture<AtomicIdGenerator> buildAsync() {
PrimitiveProxy proxy = protocol.newProxy( PrimitiveProxy proxy = protocol().newProxy(
name(), name(),
primitiveType(), primitiveType(),
managementService.getPartitionService()); managementService.getPartitionService());
Expand Down
Expand Up @@ -35,7 +35,7 @@ public DistributedLockProxyBuilder(String name, DistributedLockConfig config, Pr
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public CompletableFuture<DistributedLock> buildAsync() { public CompletableFuture<DistributedLock> buildAsync() {
PrimitiveProxy proxy = protocol.newProxy( PrimitiveProxy proxy = protocol().newProxy(
name(), name(),
primitiveType(), primitiveType(),
managementService.getPartitionService()); managementService.getPartitionService());
Expand Down
Expand Up @@ -36,16 +36,16 @@ public AtomicCounterMapProxyBuilder(String name, AtomicCounterMapConfig config,
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public CompletableFuture<AtomicCounterMap<K>> buildAsync() { public CompletableFuture<AtomicCounterMap<K>> buildAsync() {
PrimitiveProxy proxy = protocol.newProxy( PrimitiveProxy proxy = protocol().newProxy(
name(), name(),
primitiveType(), primitiveType(),
managementService.getPartitionService()); managementService.getPartitionService());
return new AtomicCounterMapProxy(proxy, managementService.getPrimitiveRegistry()) return new AtomicCounterMapProxy(proxy, managementService.getPrimitiveRegistry())
.connect() .connect()
.thenApply(multimap -> { .thenApply(map -> {
Serializer serializer = serializer(); Serializer serializer = serializer();
return new TranscodingAsyncAtomicCounterMap<K, String>( return new TranscodingAsyncAtomicCounterMap<K, String>(
multimap, map,
key -> BaseEncoding.base16().encode(serializer.encode(key)), key -> BaseEncoding.base16().encode(serializer.encode(key)),
string -> serializer.decode(BaseEncoding.base16().decode(string))) string -> serializer.decode(BaseEncoding.base16().decode(string)))
.sync(); .sync();
Expand Down
Expand Up @@ -40,7 +40,7 @@ public ConsistentMapProxyBuilder(String name, ConsistentMapConfig config, Primit
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public CompletableFuture<ConsistentMap<K, V>> buildAsync() { public CompletableFuture<ConsistentMap<K, V>> buildAsync() {
PrimitiveProxy proxy = protocol.newProxy( PrimitiveProxy proxy = protocol().newProxy(
name(), name(),
primitiveType(), primitiveType(),
managementService.getPartitionService()); managementService.getPartitionService());
Expand Down
Expand Up @@ -38,7 +38,7 @@ public ConsistentTreeMapProxyBuilder(String name, ConsistentTreeMapConfig config
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public CompletableFuture<ConsistentTreeMap<V>> buildAsync() { public CompletableFuture<ConsistentTreeMap<V>> buildAsync() {
PrimitiveProxy proxy = protocol.newProxy( PrimitiveProxy proxy = protocol().newProxy(
name(), name(),
primitiveType(), primitiveType(),
managementService.getPartitionService()); managementService.getPartitionService());
Expand Down
Expand Up @@ -38,7 +38,7 @@ public ConsistentMultimapProxyBuilder(String name, ConsistentMultimapConfig conf
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public CompletableFuture<ConsistentMultimap<K, V>> buildAsync() { public CompletableFuture<ConsistentMultimap<K, V>> buildAsync() {
PrimitiveProxy proxy = protocol.newProxy( PrimitiveProxy proxy = protocol().newProxy(
name(), name(),
primitiveType(), primitiveType(),
managementService.getPartitionService()); managementService.getPartitionService());
Expand Down
Expand Up @@ -35,7 +35,7 @@ public WorkQueueProxyBuilder(String name, WorkQueueConfig config, PrimitiveManag
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public CompletableFuture<WorkQueue<E>> buildAsync() { public CompletableFuture<WorkQueue<E>> buildAsync() {
PrimitiveProxy proxy = protocol.newProxy( PrimitiveProxy proxy = protocol().newProxy(
name(), name(),
primitiveType(), primitiveType(),
managementService.getPartitionService()); managementService.getPartitionService());
Expand Down
Expand Up @@ -43,7 +43,7 @@ public DelegatingDistributedSetBuilder(String name, DistributedSetConfig config,
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public CompletableFuture<DistributedSet<E>> buildAsync() { public CompletableFuture<DistributedSet<E>> buildAsync() {
PrimitiveProxy proxy = protocol.newProxy( PrimitiveProxy proxy = protocol().newProxy(
name(), name(),
primitiveType(), primitiveType(),
managementService.getPartitionService()); managementService.getPartitionService());
Expand Down
Expand Up @@ -38,7 +38,7 @@ public DocumentTreeProxyBuilder(String name, DocumentTreeConfig config, Primitiv
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public CompletableFuture<DocumentTree<V>> buildAsync() { public CompletableFuture<DocumentTree<V>> buildAsync() {
PrimitiveProxy proxy = protocol.newProxy( PrimitiveProxy proxy = protocol().newProxy(
name(), name(),
primitiveType(), primitiveType(),
managementService.getPartitionService()); managementService.getPartitionService());
Expand Down
Expand Up @@ -37,7 +37,7 @@ public AtomicValueProxyBuilder(String name, AtomicValueConfig config, PrimitiveM
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public CompletableFuture<AtomicValue<V>> buildAsync() { public CompletableFuture<AtomicValue<V>> buildAsync() {
PrimitiveProxy proxy = protocol.newProxy( PrimitiveProxy proxy = protocol().newProxy(
name(), name(),
primitiveType(), primitiveType(),
managementService.getPartitionService()); managementService.getPartitionService());
Expand Down
Expand Up @@ -35,7 +35,7 @@
* @param <P> primitive type * @param <P> primitive type
*/ */
public abstract class DistributedPrimitiveBuilder<B extends DistributedPrimitiveBuilder<B, C, P>, C extends PrimitiveConfig, P extends DistributedPrimitive> implements Builder<P> { public abstract class DistributedPrimitiveBuilder<B extends DistributedPrimitiveBuilder<B, C, P>, C extends PrimitiveConfig, P extends DistributedPrimitive> implements Builder<P> {
private final PrimitiveType type; protected final PrimitiveType type;
protected final String name; protected final String name;
protected final C config; protected final C config;
protected Serializer serializer; protected Serializer serializer;
Expand Down
Expand Up @@ -97,7 +97,7 @@ public PrimitiveProxy newProxy(String primitiveName, PrimitiveType primitiveType
.withConsistency(config.getConsistency()) .withConsistency(config.getConsistency())
.withReplication(config.getReplication()) .withReplication(config.getReplication())
.withRecovery(config.getRecovery()) .withRecovery(config.getRecovery())
.withNumBackups(config.getNumBackups()) .withNumBackups(config.getBackups())
.withMaxRetries(config.getMaxRetries()) .withMaxRetries(config.getMaxRetries())
.withRetryDelay(config.getRetryDelay()) .withRetryDelay(config.getRetryDelay())
.withExecutor(config.getExecutor()) .withExecutor(config.getExecutor())
Expand Down Expand Up @@ -173,7 +173,7 @@ public Builder withRecovery(Recovery recovery) {
* @return the protocol builder * @return the protocol builder
*/ */
public Builder withBackups(int numBackups) { public Builder withBackups(int numBackups) {
config.setNumBackups(numBackups); config.setBackups(numBackups);
return this; return this;
} }


Expand Down
Expand Up @@ -33,7 +33,7 @@ public class MultiPrimaryProtocolConfig extends PrimitiveProtocolConfig<MultiPri
private Consistency consistency = Consistency.SEQUENTIAL; private Consistency consistency = Consistency.SEQUENTIAL;
private Replication replication = Replication.ASYNCHRONOUS; private Replication replication = Replication.ASYNCHRONOUS;
private Recovery recovery = Recovery.RECOVER; private Recovery recovery = Recovery.RECOVER;
private int numBackups = 1; private int backups = 1;
private int maxRetries = 0; private int maxRetries = 0;
private Duration retryDelay = Duration.ofMillis(100); private Duration retryDelay = Duration.ofMillis(100);
private Executor executor; private Executor executor;
Expand Down Expand Up @@ -128,8 +128,8 @@ public MultiPrimaryProtocolConfig setRecovery(Recovery recovery) {
* *
* @return the number of backups * @return the number of backups
*/ */
public int getNumBackups() { public int getBackups() {
return numBackups; return backups;
} }


/** /**
Expand All @@ -138,8 +138,8 @@ public int getNumBackups() {
* @param numBackups the number of backups * @param numBackups the number of backups
* @return the protocol configuration * @return the protocol configuration
*/ */
public MultiPrimaryProtocolConfig setNumBackups(int numBackups) { public MultiPrimaryProtocolConfig setBackups(int numBackups) {
this.numBackups = numBackups; this.backups = numBackups;
return this; return this;
} }


Expand Down
10 changes: 7 additions & 3 deletions rest/src/test/java/io/atomix/rest/impl/VertxRestServiceTest.java
Expand Up @@ -86,7 +86,7 @@ public void testCluster() throws Exception {
.statusCode(200) .statusCode(200)
.assertThat() .assertThat()
.body("id", equalTo("1")) .body("id", equalTo("1"))
.body("type", equalTo("DATA")) .body("type", equalTo("EPHEMERAL"))
.body("host", equalTo(instances.get(0).membershipService().getLocalMember().address().host())) .body("host", equalTo(instances.get(0).membershipService().getLocalMember().address().host()))
.body("port", equalTo(instances.get(0).membershipService().getLocalMember().address().port())) .body("port", equalTo(instances.get(0).membershipService().getLocalMember().address().port()))
.body("status", equalTo("ACTIVE")); .body("status", equalTo("ACTIVE"));
Expand Down Expand Up @@ -180,10 +180,14 @@ public void testMessages() throws Exception {


@Test @Test
public void testMap() throws Exception { public void testMap() throws Exception {
JsonNode json = JsonNodeFactory.withExactBigDecimals(true).objectNode() JsonNodeFactory jsonFactory = JsonNodeFactory.withExactBigDecimals(true);
JsonNode json = jsonFactory.objectNode()
.put("type", "consistent-map") .put("type", "consistent-map")
.put("cache-enabled", true) .put("cache-enabled", true)
.put("null-values", false); .put("null-values", false)
.set("protocol", jsonFactory.objectNode()
.put("type", "multi-primary")
.put("backups", 2));


given() given()
.spec(specs.get(0)) .spec(specs.get(0))
Expand Down

0 comments on commit 869db78

Please sign in to comment.