Refactor Atomix samples (#2696)

This commit is contained in:
Grzegorz Piwowarek
2017-10-02 12:53:26 +02:00
committed by GitHub
parent 3220913767
commit 7cb94f676c
7 changed files with 114 additions and 148 deletions
@@ -0,0 +1,35 @@
package com.atomix.exampletest;
import io.atomix.AtomixClient;
import io.atomix.catalyst.transport.Address;
import io.atomix.catalyst.transport.netty.NettyTransport;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
import static org.junit.Assert.assertEquals;
public class AtomixClientLiveTest {
private final AtomixClient client = AtomixClient.builder()
.withTransport(new NettyTransport())
.build();
@Test
public void whenBootstrap_thenShouldGet() throws InterruptedException, ExecutionException {
List<Address> cluster = Arrays.asList(
new Address("localhost", 8700),
new Address("localhsot", 8701));
String value = client.connect(cluster)
.thenRun(() -> System.out.println("Client Connected"))
.thenCompose(c -> client.getMap("map"))
.thenCompose(m -> m.get("bar"))
.thenApply(a -> (String) a)
.get();
assertEquals("Hello world!", value);
}
}
@@ -1,38 +0,0 @@
package com.atomix.exampletest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import io.atomix.AtomixClient;
import io.atomix.catalyst.transport.Address;
import io.atomix.catalyst.transport.netty.NettyTransport;
import io.atomix.collections.DistributedMap;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
public class ClientExampleTest {
@Test
public void ExampleTest() throws InterruptedException {
AtomixClient client = AtomixClient.builder()
.withTransport(new NettyTransport())
.build();
List<Address> cluster = Arrays.asList(new Address("localhost", 8700), new Address("localhsot", 8701));
client.connect(cluster)
.thenRun(() -> System.out.println("Client Connected"));
Thread.sleep(5000);
DistributedMap<Object, Object> map = client.getMap("map")
.join();
String value = (String) map.get("bar")
.join();
assertEquals("Hello world!", value);
}
}