use of com.linkedin.common.callback.FutureCallback in project rest.li by linkedin.
the class SymlinkAwareZooKeeperTest method testSymlinkWithChildrenWatcher3.
// test children2Callback watcher
@Test
public void testSymlinkWithChildrenWatcher3() throws ExecutionException, InterruptedException, KeeperException {
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
Stat expectedStat1 = _zkClient.getZooKeeper().exists("/foo/bar", false);
Stat expectedStat2 = _zkClient.getZooKeeper().exists("/bar/foo", false);
final AsyncCallback.Children2Callback callback2 = new AsyncCallback.Children2Callback() {
@Override
public void processResult(int rc, String path, Object ctx, List<String> children, Stat stat) {
Assert.assertEquals(path, "/foo/$link");
Assert.assertEquals(children.size(), 5);
Assert.assertEquals(stat, expectedStat2);
latch2.countDown();
}
};
Watcher watcher = new Watcher() {
@Override
public void process(WatchedEvent event) {
Assert.assertEquals(event.getType(), Event.EventType.NodeChildrenChanged);
_zkClient.getZooKeeper().getChildren(event.getPath(), null, callback2, null);
}
};
AsyncCallback.Children2Callback callback = new AsyncCallback.Children2Callback() {
@Override
public void processResult(int rc, String path, Object ctx, List<String> children, Stat stat) {
Assert.assertEquals(stat, expectedStat1);
latch1.countDown();
}
};
// set watcher to /foo/$link
_zkClient.getZooKeeper().getChildren("/foo/$link", watcher, callback, null);
latch1.await(30, TimeUnit.SECONDS);
// update symlink
_zkClient.setSymlinkData("/foo/$link", "/bar/foo", new FutureCallback<None>());
latch2.await(30, TimeUnit.SECONDS);
FutureCallback<None> fcb = new FutureCallback<None>();
// restore symlink
_zkClient.setSymlinkData("/foo/$link", "/foo/bar", fcb);
fcb.get();
}
use of com.linkedin.common.callback.FutureCallback in project rest.li by linkedin.
the class ZKFSTest method testServiceDirectory.
@Test
public void testServiceDirectory() throws Exception {
final String TEST_SERVICE_NAME = "testingService";
startServer();
try {
ZKFSLoadBalancer balancer = getBalancer();
FutureCallback<None> callback = new FutureCallback<None>();
balancer.start(callback);
callback.get(30, TimeUnit.SECONDS);
Directory dir = balancer.getDirectory();
ZKConnection conn = new ZKConnection("localhost:" + PORT, 30000);
conn.start();
ZooKeeperPermanentStore<ServiceProperties> store = new ZooKeeperPermanentStore<ServiceProperties>(conn, new ServicePropertiesJsonSerializer(), ZKFSUtil.servicePath(BASE_PATH));
callback = new FutureCallback<None>();
store.start(callback);
callback.get(30, TimeUnit.SECONDS);
ServiceProperties props = new ServiceProperties(TEST_SERVICE_NAME, "someCluster", "/somePath", Arrays.asList("someStrategy"));
store.put(TEST_SERVICE_NAME, props);
FutureCallback<List<String>> serviceCallback = new FutureCallback<List<String>>();
dir.getServiceNames(serviceCallback);
Assert.assertEquals(serviceCallback.get(30, TimeUnit.SECONDS), Collections.singletonList(TEST_SERVICE_NAME));
} finally {
stopServer();
}
}
use of com.linkedin.common.callback.FutureCallback in project rest.li by linkedin.
the class ZKFSTest method testClusterDirectory.
@Test
public void testClusterDirectory() throws Exception {
final String TEST_CLUSTER_NAME = "testingService";
startServer();
try {
ZKFSLoadBalancer balancer = getBalancer();
FutureCallback<None> callback = new FutureCallback<None>();
balancer.start(callback);
callback.get(30, TimeUnit.SECONDS);
Directory dir = balancer.getDirectory();
ZKConnection conn = new ZKConnection("localhost:" + PORT, 30000);
conn.start();
ZooKeeperPermanentStore<ClusterProperties> store = new ZooKeeperPermanentStore<ClusterProperties>(conn, new ClusterPropertiesJsonSerializer(), ZKFSUtil.clusterPath(BASE_PATH));
callback = new FutureCallback<None>();
store.start(callback);
callback.get(30, TimeUnit.SECONDS);
ClusterProperties props = new ClusterProperties(TEST_CLUSTER_NAME);
store.put(TEST_CLUSTER_NAME, props);
FutureCallback<List<String>> clusterCallback = new FutureCallback<List<String>>();
dir.getClusterNames(clusterCallback);
Assert.assertEquals(clusterCallback.get(30, TimeUnit.SECONDS), Collections.singletonList(TEST_CLUSTER_NAME));
} finally {
stopServer();
}
}
use of com.linkedin.common.callback.FutureCallback in project rest.li by linkedin.
the class TestMIMEWriter method testPrependDataSources.
@Test(dataProvider = "prependDataSources")
public void testPrependDataSources(final MultiPartMIMEWriter.Builder builder, final List<MultiPartMIMEDataSourceWriter> prependDataSources, final List<MIMEDataPart> expectedParts, final String expectedPreamble, final int expectedSize) throws Exception {
for (final MultiPartMIMEDataSourceWriter dataSourceWriter : prependDataSources) {
builder.prependDataSource(dataSourceWriter);
}
Assert.assertEquals(builder.getCurrentSize(), expectedSize);
final MultiPartMIMEWriter writer = builder.build();
final FutureCallback<ByteString> futureCallback = new FutureCallback<ByteString>();
final FullEntityReader fullEntityReader = new FullEntityReader(futureCallback);
writer.getEntityStream().setReader(fullEntityReader);
futureCallback.get(_testTimeout, TimeUnit.MILLISECONDS);
final StreamRequest multiPartMIMEStreamRequest = MultiPartMIMEStreamRequestFactory.generateMultiPartMIMEStreamRequest(URI.create("localhost"), "mixed", writer, Collections.<String, String>emptyMap());
final JavaxMailMultiPartMIMEReader javaxMailMultiPartMIMEReader = new JavaxMailMultiPartMIMEReader(multiPartMIMEStreamRequest.getHeader(MultiPartMIMEUtils.CONTENT_TYPE_HEADER), futureCallback.get());
javaxMailMultiPartMIMEReader.parseRequestIntoParts();
List<MIMEDataPart> dataSourceList = javaxMailMultiPartMIMEReader._dataSourceList;
Assert.assertEquals(dataSourceList.size(), 3);
for (int i = 0; i < dataSourceList.size(); i++) {
Assert.assertEquals(dataSourceList.get(i), expectedParts.get(i));
}
//Javax mail incorrectly adds the CRLF for the first boundary to the end of the preamble, so we trim
Assert.assertEquals(javaxMailMultiPartMIMEReader._preamble != null ? javaxMailMultiPartMIMEReader._preamble.trim() : null, expectedPreamble);
}
use of com.linkedin.common.callback.FutureCallback in project rest.li by linkedin.
the class TestMIMEWriter method testSingleDataSource.
@Test(dataProvider = "singleDataSources")
public void testSingleDataSource(final ByteString body, final Map<String, String> headers) throws Exception {
final MIMEDataPart expectedMultiPartMIMEDataPart = new MIMEDataPart(body, headers);
final MultiPartMIMEInputStream singleDataSource = new MultiPartMIMEInputStream.Builder(new ByteArrayInputStream(body.copyBytes()), _scheduledExecutorService, headers).build();
final MultiPartMIMEWriter multiPartMIMEWriter = new MultiPartMIMEWriter.Builder("preamble", "epilogue").appendDataSource(singleDataSource).build();
final FutureCallback<ByteString> futureCallback = new FutureCallback<ByteString>();
final FullEntityReader fullEntityReader = new FullEntityReader(futureCallback);
multiPartMIMEWriter.getEntityStream().setReader(fullEntityReader);
futureCallback.get(_testTimeout, TimeUnit.MILLISECONDS);
final StreamRequest multiPartMIMEStreamRequest = MultiPartMIMEStreamRequestFactory.generateMultiPartMIMEStreamRequest(URI.create("localhost"), "mixed", multiPartMIMEWriter, Collections.<String, String>emptyMap());
JavaxMailMultiPartMIMEReader javaxMailMultiPartMIMEReader = new JavaxMailMultiPartMIMEReader(multiPartMIMEStreamRequest.getHeader(MultiPartMIMEUtils.CONTENT_TYPE_HEADER), futureCallback.get());
javaxMailMultiPartMIMEReader.parseRequestIntoParts();
List<MIMEDataPart> dataSourceList = javaxMailMultiPartMIMEReader._dataSourceList;
Assert.assertEquals(dataSourceList.size(), 1);
Assert.assertEquals(dataSourceList.get(0), expectedMultiPartMIMEDataPart);
//Javax mail incorrectly adds the CRLF for the first boundary to the end of the preamble, so we trim
Assert.assertEquals(javaxMailMultiPartMIMEReader._preamble.trim(), "preamble");
}
Aggregations