當前位置: 首頁>>代碼示例>>Java>>正文


Java ConcurrentNavigableMap.firstKey方法代碼示例

本文整理匯總了Java中java.util.concurrent.ConcurrentNavigableMap.firstKey方法的典型用法代碼示例。如果您正苦於以下問題:Java ConcurrentNavigableMap.firstKey方法的具體用法?Java ConcurrentNavigableMap.firstKey怎麽用?Java ConcurrentNavigableMap.firstKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.ConcurrentNavigableMap的用法示例。


在下文中一共展示了ConcurrentNavigableMap.firstKey方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: resolveByUuid

import java.util.concurrent.ConcurrentNavigableMap; //導入方法依賴的package包/類
@Override
public Optional<ServerAddress> resolveByUuid(UUID uuid) {
  Assert.notNull(uuid);
  if (circle.isEmpty()) {
    return Optional.empty();
  }
  Long hash = hashFunction.newHasher().putLong(uuid.getMostSignificantBits()).putLong(uuid.getLeastSignificantBits())
      .hash().asLong();
  if (!circle.containsKey(hash)) {
    ConcurrentNavigableMap<Long, ServerInstance> tailMap = circle.tailMap(hash);
    hash = tailMap.isEmpty() ? circle.firstKey() : tailMap.firstKey();
  }
  ServerInstance result = circle.get(hash);
  if (!currentServer.equals(result)) {
    return Optional.of(result.getServerAddress());
  } else {
    return Optional.empty();
  }
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:20,代碼來源:ConsistentClusterRoutingService.java

示例2: testCheckCommit

import java.util.concurrent.ConcurrentNavigableMap; //導入方法依賴的package包/類
@Test
// Validate all the commit check return codes OpenFileCtx.COMMIT_STATUS, which
// includes COMMIT_FINISHED, COMMIT_WAIT, COMMIT_INACTIVE_CTX,
// COMMIT_INACTIVE_WITH_PENDING_WRITE, COMMIT_ERROR, and COMMIT_DO_SYNC.
public void testCheckCommit() throws IOException {
  DFSClient dfsClient = Mockito.mock(DFSClient.class);
  Nfs3FileAttributes attr = new Nfs3FileAttributes();
  HdfsDataOutputStream fos = Mockito.mock(HdfsDataOutputStream.class);
  Mockito.when(fos.getPos()).thenReturn((long) 0);

  NfsConfiguration conf = new NfsConfiguration();
  conf.setBoolean(NfsConfigKeys.LARGE_FILE_UPLOAD, false);
  OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient,
      new ShellBasedIdMapping(conf), false, conf);

  COMMIT_STATUS ret;

  // Test inactive open file context
  ctx.setActiveStatusForTest(false);
  Channel ch = Mockito.mock(Channel.class);
  ret = ctx.checkCommit(dfsClient, 0, ch, 1, attr, false);
  Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_INACTIVE_CTX);

  ctx.getPendingWritesForTest().put(new OffsetRange(5, 10),
      new WriteCtx(null, 0, 0, 0, null, null, null, 0, false, null));
  ret = ctx.checkCommit(dfsClient, 0, ch, 1, attr, false);
  Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_INACTIVE_WITH_PENDING_WRITE);

  // Test request with non zero commit offset
  ctx.setActiveStatusForTest(true);
  Mockito.when(fos.getPos()).thenReturn((long) 10);
  ctx.setNextOffsetForTest(10);
  COMMIT_STATUS status = ctx.checkCommitInternal(5, null, 1, attr, false);
  Assert.assertTrue(status == COMMIT_STATUS.COMMIT_DO_SYNC);
  // Do_SYNC state will be updated to FINISHED after data sync
  ret = ctx.checkCommit(dfsClient, 5, ch, 1, attr, false);
  Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_FINISHED);
  
  status = ctx.checkCommitInternal(10, ch, 1, attr, false);
  Assert.assertTrue(status == COMMIT_STATUS.COMMIT_DO_SYNC);
  ret = ctx.checkCommit(dfsClient, 10, ch, 1, attr, false);
  Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_FINISHED);

  ConcurrentNavigableMap<Long, CommitCtx> commits = ctx
      .getPendingCommitsForTest();
  Assert.assertTrue(commits.size() == 0);
  ret = ctx.checkCommit(dfsClient, 11, ch, 1, attr, false);
  Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_WAIT);
  Assert.assertTrue(commits.size() == 1);
  long key = commits.firstKey();
  Assert.assertTrue(key == 11);

  // Test request with zero commit offset
  commits.remove(new Long(11));
  // There is one pending write [5,10]
  ret = ctx.checkCommit(dfsClient, 0, ch, 1, attr, false);
  Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_WAIT);
  Assert.assertTrue(commits.size() == 1);
  key = commits.firstKey();
  Assert.assertTrue(key == 9);

  // Empty pending writes
  ctx.getPendingWritesForTest().remove(new OffsetRange(5, 10));
  ret = ctx.checkCommit(dfsClient, 0, ch, 1, attr, false);
  Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_FINISHED);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:67,代碼來源:TestWrites.java


注:本文中的java.util.concurrent.ConcurrentNavigableMap.firstKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。