use of io.atomix.primitive.PrimitiveInfo in project atomix by atomix.
the class CorePrimitiveRegistry method createPrimitive.
@Override
public CompletableFuture<PrimitiveInfo> createPrimitive(String name, PrimitiveType type) {
PrimitiveInfo info = new PrimitiveInfo(name, type);
CompletableFuture<PrimitiveInfo> future = new CompletableFuture<>();
primitives.putIfAbsent(name, type.name()).whenComplete((result, error) -> {
if (error != null) {
future.completeExceptionally(error);
} else if (result == null || result.value().equals(type.name())) {
future.complete(info);
} else {
future.completeExceptionally(new PrimitiveException("A different primitive with the same name already exists"));
}
});
return future;
}
use of io.atomix.primitive.PrimitiveInfo in project atomix by atomix.
the class RaftTest method createPrimitive.
/**
* Creates a new primitive instance.
*/
private TestPrimitive createPrimitive(RaftClient client, ReadConsistency consistency) throws Exception {
SessionClient partition = createSession(client, consistency);
ProxyClient<TestPrimitiveService> proxy = new DefaultProxyClient<>("test", TestPrimitiveType.INSTANCE, MultiRaftProtocol.builder().build(), TestPrimitiveService.class, Collections.singletonList(partition), (key, partitions) -> partitions.get(0));
PrimitiveRegistry registry = mock(PrimitiveRegistry.class);
when(registry.createPrimitive(any(String.class), any(PrimitiveType.class))).thenReturn(CompletableFuture.completedFuture(new PrimitiveInfo("raft-test", TestPrimitiveType.INSTANCE)));
when(registry.deletePrimitive(any(String.class))).thenReturn(CompletableFuture.completedFuture(null));
return new TestPrimitiveImpl(proxy, registry);
}
Aggregations