com.twitter.util.Await.result()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中com.twitter.util.Await.result()方法的一些代码示例,展示了Await.result()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Await.result()方法的具体详情如下:
包路径:com.twitter.util.Await
类名称:Await
方法名:result

Await.result介绍

暂无

代码示例

代码示例来源:origin: twitter/distributedlog

@Override
protected int runCmd(Pair<DistributedLogClient, MonitorServiceClient> client)
    throws Exception {
  Await.result(client.getRight().setAcceptNewStream(enabled));
  return 0;
}

代码示例来源:origin: twitter/distributedlog

@Override
public void unlock() {
  Future<BoxedUnit> unlockResult = asyncUnlock();
  try {
    Await.result(unlockResult, Duration.fromMilliseconds(lockOpTimeout));
  } catch (TimeoutException toe) {
    // This shouldn't happen unless we lose a watch, and may result in a leaked lock.
    LOG.error("Timeout unlocking {} owned by {} : ", new Object[] { lockPath, lockId, toe });
  } catch (Exception e) {
    LOG.warn("{} failed to unlock {} : ", new Object[] { lockId, lockPath, e });
  }
}

代码示例来源:origin: twitter/distributedlog

public void markEndOfStream() throws IOException {
  try {
    Await.result(logWriter.markEndOfStream());
  } catch (IOException ioe) {
    throw ioe;
  } catch (Exception ex) {
    throw new UnexpectedException("Mark end of stream hit unexpected exception", ex);
  }
}

代码示例来源:origin: twitter/distributedlog

public static <T> void validateFutureFailed(Future<T> future, Class exClass) {
  try {
    Await.result(future);
  } catch (Exception ex) {
    LOG.info("Expected: {} Actual: {}", exClass.getName(), ex.getClass().getName());
    assertTrue("exceptions types equal", exClass.isInstance(ex));
  }
}

代码示例来源:origin: twitter/distributedlog

private void readEntries(AsyncLogReader reader) {
  try {
    for (int i = 0; i < 300; i++) {
      LogRecordWithDLSN record = Await.result(reader.readNext());
      currentDLSN.set(record.getDlsn());
    }
  } catch (Exception ex) {
    failed = true;
  } finally {
    latch.countDown();
  }
}

代码示例来源:origin: twitter/distributedlog

protected ZKAccessControl getZKAccessControl(ZooKeeperClient zkc, String zkPath) throws Exception {
  ZKAccessControl accessControl;
  try {
    accessControl = Await.result(ZKAccessControl.read(zkc, zkPath, null));
  } catch (KeeperException.NoNodeException nne) {
    accessControl = new ZKAccessControl(new AccessControlEntry(), zkPath);
  }
  return accessControl;
}

代码示例来源:origin: twitter/distributedlog

public static <T> T validateFutureSucceededAndGetResult(Future<T> future) throws Exception {
    try {
      return Await.result(future, Duration.fromSeconds(10));
    } catch (Exception ex) {
      fail("unexpected exception " + ex.getClass().getName());
      throw ex;
    }
  }
}

代码示例来源:origin: twitter/distributedlog

@Test(timeout = 60000)
public void testGetLogRecordCountAtLedgerBoundary() throws Exception {
  String dlName = runtime.getMethodName();
  prepareLogSegmentsNonPartitioned(dlName, 11, 3);
  DistributedLogManager dlm = createNewDLM(conf, dlName);
  BKLogReadHandler readHandler = ((BKDistributedLogManager) dlm).createReadHandler();
  Future<Long> count = null;
  count = readHandler.asyncGetLogRecordCount(new DLSN(2, 0, 0));
  assertEquals(30, Await.result(count).longValue());
  count = readHandler.asyncGetLogRecordCount(new DLSN(3, 0, 0));
  assertEquals(27, Await.result(count).longValue());
}

代码示例来源:origin: twitter/distributedlog

@Test(timeout = 60000)
public void testGetLogRecordCountInteriorRecords() throws Exception {
  String dlName = runtime.getMethodName();
  prepareLogSegmentsNonPartitioned(dlName, 5, 10);
  DistributedLogManager dlm = createNewDLM(conf, dlName);
  BKLogReadHandler readHandler = ((BKDistributedLogManager) dlm).createReadHandler();
  Future<Long> count = null;
  count = readHandler.asyncGetLogRecordCount(new DLSN(3, 5, 0));
  assertEquals(25, Await.result(count).longValue());
  count = readHandler.asyncGetLogRecordCount(new DLSN(2, 5, 0));
  assertEquals(35, Await.result(count).longValue());
}

代码示例来源:origin: twitter/distributedlog

@Test(timeout = 60000)
public void testGetLogRecordCountTotalCount() throws Exception {
  String dlName = runtime.getMethodName();
  prepareLogSegmentsNonPartitioned(dlName, 11, 3);
  DistributedLogManager dlm = createNewDLM(conf, dlName);
  BKLogReadHandler readHandler = ((BKDistributedLogManager) dlm).createReadHandler();
  Future<Long> count = null;
  count = readHandler.asyncGetLogRecordCount(DLSN.InitialDLSN);
  assertEquals(33, Await.result(count).longValue());
}

代码示例来源:origin: twitter/distributedlog

@Test(timeout = 60000)
public void testGetLogRecordCountPastEnd() throws Exception {
  String dlName = runtime.getMethodName();
  prepareLogSegmentsNonPartitioned(dlName, 11, 3);
  DistributedLogManager dlm = createNewDLM(conf, dlName);
  BKLogReadHandler readHandler = ((BKDistributedLogManager) dlm).createReadHandler();
  Future<Long> count = null;
  count = readHandler.asyncGetLogRecordCount(new DLSN(12, 0, 0));
  assertEquals(0, Await.result(count).longValue());
}

代码示例来源:origin: twitter/distributedlog

@Test(timeout = 60000)
public void testGetFirstDLSNNoLogSegments() throws Exception {
  String dlName = runtime.getMethodName();
  BKDistributedLogManager dlm = createNewDLM(conf, dlName);
  BKLogReadHandler readHandler = dlm.createReadHandler();
  Future<LogRecordWithDLSN> futureRecord = readHandler.asyncGetFirstLogRecord();
  try {
    Await.result(futureRecord);
    fail("should have thrown exception");
  } catch (LogNotFoundException ex) {
  }
}

代码示例来源:origin: twitter/distributedlog

@Test(timeout = 60000)
public void testGetLogRecordCountWithAllControlRecords() throws Exception {
  DistributedLogManager dlm = createNewDLM(conf, runtime.getMethodName());
  long txid = 1;
  txid += DLMTestUtil.generateLogSegmentNonPartitioned(dlm, 5, 0, txid);
  txid += DLMTestUtil.generateLogSegmentNonPartitioned(dlm, 10, 0, txid);
  BKLogReadHandler readHandler = ((BKDistributedLogManager) dlm).createReadHandler();
  Future<Long> count = null;
  count = readHandler.asyncGetLogRecordCount(new DLSN(1, 0, 0));
  assertEquals(0, Await.result(count).longValue());
}

代码示例来源:origin: twitter/distributedlog

@Test(timeout = 60000)
public void testGetLogRecordCountWithControlRecords() throws Exception {
  DistributedLogManager dlm = createNewDLM(conf, runtime.getMethodName());
  long txid = 1;
  txid += DLMTestUtil.generateLogSegmentNonPartitioned(dlm, 5, 5, txid);
  txid += DLMTestUtil.generateLogSegmentNonPartitioned(dlm, 0, 10, txid);
  BKLogReadHandler readHandler = ((BKDistributedLogManager) dlm).createReadHandler();
  Future<Long> count = null;
  count = readHandler.asyncGetLogRecordCount(new DLSN(1, 0, 0));
  assertEquals(15, Await.result(count).longValue());
}

代码示例来源:origin: twitter/distributedlog

@Test(timeout = 60000)
public void testEmptyZKAccessControl() throws Exception {
  String zkPath = "/empty-access-control";
  zkc.get().create(zkPath, new byte[0], zkc.getDefaultACL(), CreateMode.PERSISTENT);
  ZKAccessControl readZKAC = Await.result(ZKAccessControl.read(zkc, zkPath, null));
  assertEquals(zkPath, readZKAC.zkPath);
  assertEquals(ZKAccessControl.DEFAULT_ACCESS_CONTROL_ENTRY, readZKAC.getAccessControlEntry());
  assertTrue(ZKAccessControl.DEFAULT_ACCESS_CONTROL_ENTRY == readZKAC.getAccessControlEntry());
}

代码示例来源:origin: twitter/distributedlog

@Test(timeout = 60000)
public void testGetLogRecordCountAsync() throws Exception {
  DistributedLogManager dlm = createNewDLM(conf, testNames.getMethodName());
  BKAsyncLogWriter writer = (BKAsyncLogWriter) dlm.startAsyncLogSegmentNonPartitioned();
  DLMTestUtil.generateCompletedLogSegments(dlm, conf, 2, 10);
  Future<Long> futureCount = dlm.getLogRecordCountAsync(DLSN.InitialDLSN);
  Long count = Await.result(futureCount, Duration.fromSeconds(2));
  assertEquals(20, count.longValue());
  writer.close();
  dlm.close();
}

代码示例来源:origin: twitter/distributedlog

@Test(timeout = 60000)
public void testForwardScanNotFirstRecord() throws Exception {
  String streamName = runtime.getMethodName();
  BKDistributedLogManager bkdlm = (BKDistributedLogManager) createNewDLM(conf, streamName);
  DLMTestUtil.generateLogSegmentNonPartitioned(bkdlm, 0, 5, 1 /* txid */);
  DLSN dlsn = new DLSN(1,1,0);
  Future<LogRecordWithDLSN> futureLogrec = getFirstGreaterThanRecord(bkdlm, 0, dlsn);
  LogRecordWithDLSN logrec = Await.result(futureLogrec);
  assertEquals("should be an exact match", dlsn, logrec.getDlsn());
  bkdlm.close();
}

代码示例来源:origin: twitter/distributedlog

@Test(timeout = 60000)
public void testGetLastRecordUserRecord() throws Exception {
  String streamName = runtime.getMethodName();
  BKDistributedLogManager bkdlm = (BKDistributedLogManager) createNewDLM(conf, streamName);
  DLMTestUtil.generateLogSegmentNonPartitioned(bkdlm, 5 /* control recs */, 5, 1 /* txid */);
  Future<LogRecordWithDLSN> futureLogrec = getLastUserRecord(bkdlm, 0);
  LogRecordWithDLSN logrec = Await.result(futureLogrec);
  assertEquals(new DLSN(1,9,0), logrec.getDlsn());
  bkdlm.close();
}

代码示例来源:origin: twitter/distributedlog

@Test(timeout = 60000)
public void testForwardScanValidButNonExistentRecord() throws Exception {
  String streamName = runtime.getMethodName();
  BKDistributedLogManager bkdlm = (BKDistributedLogManager) createNewDLM(conf, streamName);
  DLMTestUtil.generateLogSegmentNonPartitioned(bkdlm, 0, 5, 1 /* txid */);
  DLSN dlsn = new DLSN(1,0,1);
  Future<LogRecordWithDLSN> futureLogrec = getFirstGreaterThanRecord(bkdlm, 0, dlsn);
  LogRecordWithDLSN logrec = Await.result(futureLogrec);
  assertEquals(new DLSN(1,1,0), logrec.getDlsn());
  bkdlm.close();
}

代码示例来源:origin: twitter/distributedlog

@Test(timeout = 60000)
public void testForwardScanControlRecord() throws Exception {
  String streamName = runtime.getMethodName();
  BKDistributedLogManager bkdlm = (BKDistributedLogManager) createNewDLM(conf, streamName);
  DLMTestUtil.generateLogSegmentNonPartitioned(bkdlm, 5 /* control recs */, 5, 1 /* txid */);
  DLSN dlsn = new DLSN(1,3,0);
  Future<LogRecordWithDLSN> futureLogrec = getFirstGreaterThanRecord(bkdlm, 0, dlsn);
  LogRecordWithDLSN logrec = Await.result(futureLogrec);
  assertEquals(new DLSN(1,5,0), logrec.getDlsn());
  bkdlm.close();
}

相关文章

微信公众号

最新文章

更多