use of com.twitter.distributedlog.DLSN in project distributedlog by twitter.
the class TestDistributedLogService method testTruncateOpNoChecksum.
@Test(timeout = 60000)
public void testTruncateOpNoChecksum() throws Exception {
DistributedLogServiceImpl localService = createConfiguredLocalService();
WriteContext ctx = new WriteContext();
Future<WriteResponse> result = localService.truncate("test", new DLSN(1, 2, 3).serialize(), ctx);
WriteResponse resp = Await.result(result);
assertEquals(StatusCode.SUCCESS, resp.getHeader().getCode());
localService.shutdown();
}
use of com.twitter.distributedlog.DLSN in project distributedlog by twitter.
the class ConsoleProxyPartitionedMultiWriter method main.
public static void main(String[] args) throws Exception {
if (2 != args.length) {
System.out.println(HELP);
return;
}
String finagleNameStr = args[0];
final String streamList = args[1];
DistributedLogClient client = DistributedLogClientBuilder.newBuilder().clientId(ClientId$.MODULE$.apply("console-proxy-writer")).name("console-proxy-writer").thriftmux(true).finagleNameStr(finagleNameStr).build();
String[] streamNameList = StringUtils.split(streamList, ',');
PartitionedWriter<Integer, String> partitionedWriter = new PartitionedWriter<Integer, String>(streamNameList, new IntPartitioner(), client);
ConsoleReader reader = new ConsoleReader();
String line;
while ((line = reader.readLine(PROMPT_MESSAGE)) != null) {
String[] parts = StringUtils.split(line, ':');
if (parts.length != 2) {
System.out.println("Invalid input. Needs 'KEY:VALUE'");
continue;
}
int key;
try {
key = Integer.parseInt(parts[0]);
} catch (NumberFormatException nfe) {
System.out.println("Invalid input. Needs 'KEY:VALUE'");
continue;
}
String value = parts[1];
partitionedWriter.write(key, value).addEventListener(new FutureEventListener<DLSN>() {
@Override
public void onFailure(Throwable cause) {
System.out.println("Encountered error on writing data");
cause.printStackTrace(System.err);
Runtime.getRuntime().exit(0);
}
@Override
public void onSuccess(DLSN value) {
// done
}
});
}
client.close();
}
use of com.twitter.distributedlog.DLSN in project distributedlog by twitter.
the class ConsoleProxyRRMultiWriter method main.
public static void main(String[] args) throws Exception {
if (2 != args.length) {
System.out.println(HELP);
return;
}
String finagleNameStr = args[0];
final String streamList = args[1];
DistributedLogClient client = DistributedLogClientBuilder.newBuilder().clientId(ClientId$.MODULE$.apply("console-proxy-writer")).name("console-proxy-writer").thriftmux(true).finagleNameStr(finagleNameStr).build();
String[] streamNameList = StringUtils.split(streamList, ',');
RRMultiWriter<Integer, String> writer = new RRMultiWriter(streamNameList, client);
ConsoleReader reader = new ConsoleReader();
String line;
while ((line = reader.readLine(PROMPT_MESSAGE)) != null) {
writer.write(line).addEventListener(new FutureEventListener<DLSN>() {
@Override
public void onFailure(Throwable cause) {
System.out.println("Encountered error on writing data");
cause.printStackTrace(System.err);
Runtime.getRuntime().exit(0);
}
@Override
public void onSuccess(DLSN value) {
// done
}
});
}
client.close();
}
use of com.twitter.distributedlog.DLSN in project distributedlog by twitter.
the class TestDistributedLogService method testTruncateOpChecksumBadChecksum.
@Test(timeout = 60000)
public void testTruncateOpChecksumBadChecksum() throws Exception {
DistributedLogServiceImpl localService = createConfiguredLocalService();
WriteContext ctx = new WriteContext().setCrc32(999);
Future<WriteResponse> result = localService.truncate("test", new DLSN(1, 2, 3).serialize(), ctx);
WriteResponse resp = Await.result(result);
assertEquals(StatusCode.CHECKSUM_FAILED, resp.getHeader().getCode());
localService.shutdown();
}
use of com.twitter.distributedlog.DLSN in project distributedlog by twitter.
the class ZKSubscriptionStateStore method getLastCommitPositionFromZK.
Future<DLSN> getLastCommitPositionFromZK() {
final Promise<DLSN> result = new Promise<DLSN>();
try {
logger.debug("Reading last commit position from path {}", zkPath);
zooKeeperClient.get().getData(zkPath, false, new AsyncCallback.DataCallback() {
@Override
public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
logger.debug("Read last commit position from path {}: rc = {}", zkPath, rc);
if (KeeperException.Code.NONODE.intValue() == rc) {
result.setValue(DLSN.NonInclusiveLowerBound);
} else if (KeeperException.Code.OK.intValue() != rc) {
result.setException(KeeperException.create(KeeperException.Code.get(rc), path));
} else {
try {
DLSN dlsn = DLSN.deserialize(new String(data, Charsets.UTF_8));
result.setValue(dlsn);
} catch (Exception t) {
logger.warn("Invalid last commit position found from path {}", zkPath, t);
// invalid dlsn recorded in subscription state store
result.setValue(DLSN.NonInclusiveLowerBound);
}
}
}
}, null);
} catch (ZooKeeperClient.ZooKeeperConnectionException zkce) {
result.setException(zkce);
} catch (InterruptedException ie) {
result.setException(new DLInterruptedException("getLastCommitPosition was interrupted", ie));
}
return result;
}
Aggregations