Java Code Examples for java.util.concurrent.ConcurrentNavigableMap#remove()

The following examples show how to use java.util.concurrent.ConcurrentNavigableMap#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConcurrentSkipListSubMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * pollLastEntry returns entries in order
 */
public void testPollLastEntry() {
    ConcurrentNavigableMap map = map5();
    Map.Entry e = map.pollLastEntry();
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(four, e.getKey());
    map.put(five, "E");
    e = map.pollLastEntry();
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(three, e.getKey());
    map.remove(two);
    e = map.pollLastEntry();
    assertEquals(one, e.getKey());
    try {
        e.setValue("E");
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
    e = map.pollLastEntry();
    assertNull(e);
}
 
Example 2
Source File: ConcurrentSkipListSubMapJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * pollFirstEntry returns entries in order
 */
public void testPollFirstEntry() {
    ConcurrentNavigableMap map = map5();
    Map.Entry e = map.pollFirstEntry();
    assertEquals(one, e.getKey());
    assertEquals("A", e.getValue());
    e = map.pollFirstEntry();
    assertEquals(two, e.getKey());
    map.put(one, "A");
    e = map.pollFirstEntry();
    assertEquals(one, e.getKey());
    assertEquals("A", e.getValue());
    e = map.pollFirstEntry();
    assertEquals(three, e.getKey());
    map.remove(four);
    e = map.pollFirstEntry();
    assertEquals(five, e.getKey());
    try {
        e.setValue("A");
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
    e = map.pollFirstEntry();
    assertNull(e);
}
 
Example 3
Source File: ConcurrentSkipListSubMapTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * pollLastEntry returns entries in order
 */
public void testPollLastEntry() {
    ConcurrentNavigableMap map = map5();
    Map.Entry e = map.pollLastEntry();
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(four, e.getKey());
    map.put(five, "E");
    e = map.pollLastEntry();
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(three, e.getKey());
    map.remove(two);
    e = map.pollLastEntry();
    assertEquals(one, e.getKey());
    try {
        e.setValue("E");
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
    e = map.pollLastEntry();
    assertNull(e);
}
 
Example 4
Source File: ConcurrentSkipListSubMapTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * pollFirstEntry returns entries in order
 */
public void testPollFirstEntry() {
    ConcurrentNavigableMap map = map5();
    Map.Entry e = map.pollFirstEntry();
    assertEquals(one, e.getKey());
    assertEquals("A", e.getValue());
    e = map.pollFirstEntry();
    assertEquals(two, e.getKey());
    map.put(one, "A");
    e = map.pollFirstEntry();
    assertEquals(one, e.getKey());
    assertEquals("A", e.getValue());
    e = map.pollFirstEntry();
    assertEquals(three, e.getKey());
    map.remove(four);
    e = map.pollFirstEntry();
    assertEquals(five, e.getKey());
    try {
        e.setValue("A");
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
    e = map.pollFirstEntry();
    assertNull(e);
}
 
Example 5
Source File: ConcurrentSkipListSubMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * pollLastEntry returns entries in order
 */
public void testDescendingPollLastEntry() {
    ConcurrentNavigableMap map = dmap5();
    Map.Entry e = map.pollLastEntry();
    assertEquals(m5, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(m4, e.getKey());
    map.put(m5, "E");
    e = map.pollLastEntry();
    assertEquals(m5, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(m3, e.getKey());
    map.remove(m2);
    e = map.pollLastEntry();
    assertEquals(m1, e.getKey());
    try {
        e.setValue("E");
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
    e = map.pollLastEntry();
    assertNull(e);
}
 
Example 6
Source File: ConcurrentSkipListSubMapJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * pollFirstEntry returns entries in order
 */
public void testPollFirstEntry() {
    ConcurrentNavigableMap map = map5();
    Map.Entry e = map.pollFirstEntry();
    assertEquals(one, e.getKey());
    assertEquals("A", e.getValue());
    e = map.pollFirstEntry();
    assertEquals(two, e.getKey());
    map.put(one, "A");
    e = map.pollFirstEntry();
    assertEquals(one, e.getKey());
    assertEquals("A", e.getValue());
    e = map.pollFirstEntry();
    assertEquals(three, e.getKey());
    map.remove(four);
    e = map.pollFirstEntry();
    assertEquals(five, e.getKey());
    try {
        e.setValue("A");
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
    e = map.pollFirstEntry();
    assertNull(e);
}
 
Example 7
Source File: BTreeMapTest5.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * remove(null, x) throws NPE
 */
public void testRemove2_NullPointerException() {
    try {
        ConcurrentNavigableMap c = map5();
        c.remove(null, "whatever");
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 8
Source File: ConcurrentSkipListSubMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * remove(null) throws NPE
 */
public void testDescendingRemove1_NullPointerException() {
    try {
        ConcurrentNavigableMap c = dmap5();
        c.remove(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 9
Source File: ConcurrentSkipListSubMapJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * remove(null) throws NPE
 */
public void testRemove1_NullPointerException() {
    try {
        ConcurrentNavigableMap c = map5();
        c.remove(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 10
Source File: BTreeMapTest5.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * remove(key,value) removes only if pair present
 */
public void testRemove2() {
    ConcurrentNavigableMap map = map5();
    assertTrue(map.containsKey(five));
    assertEquals("E", map.get(five));
    map.remove(five, "E");
    assertEquals(4, map.size());
    assertFalse(map.containsKey(five));
    map.remove(four, "A");
    assertEquals(4, map.size());
    assertTrue(map.containsKey(four));
}
 
Example 11
Source File: ConcurrentSkipListSubMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * remove(null, x) throws NPE
 */
public void testDescendingRemove2_NullPointerException() {
    try {
        ConcurrentNavigableMap c = dmap5();
        c.remove(null, "whatever");
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 12
Source File: ConcurrentSkipListSubMapJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * remove removes the correct key-value pair from the map
 */
public void testRemove() {
    ConcurrentNavigableMap map = map5();
    map.remove(five);
    assertEquals(4, map.size());
    assertFalse(map.containsKey(five));
}
 
Example 13
Source File: ConcurrentSkipListSubMapJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * remove(key,value) removes only if pair present
 */
public void testRemove2() {
    ConcurrentNavigableMap map = map5();
    assertTrue(map.containsKey(five));
    assertEquals("E", map.get(five));
    map.remove(five, "E");
    assertEquals(4, map.size());
    assertFalse(map.containsKey(five));
    map.remove(four, "A");
    assertEquals(4, map.size());
    assertTrue(map.containsKey(four));
}
 
Example 14
Source File: ConcurrentSkipListSubMapJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * remove(null, x) throws NPE
 */
public void testDescendingRemove2_NullPointerException() {
    try {
        ConcurrentNavigableMap c = dmap5();
        c.remove(null, "whatever");
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 15
Source File: ConcurrentSkipListSubMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * remove(null, x) throws NPE
 */
public void testRemove2_NullPointerException() {
    try {
        ConcurrentNavigableMap c = map5();
        c.remove(null, "whatever");
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 16
Source File: ConcurrentSkipListSubMapJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * remove(key,value) removes only if pair present
 */
public void testDescendingRemove2() {
    ConcurrentNavigableMap map = dmap5();
    assertTrue(map.containsKey(m5));
    assertEquals("E", map.get(m5));
    map.remove(m5, "E");
    assertEquals(4, map.size());
    assertFalse(map.containsKey(m5));
    map.remove(m4, "A");
    assertEquals(4, map.size());
    assertTrue(map.containsKey(m4));
}
 
Example 17
Source File: ConcurrentSkipListSubMapJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * remove(null, x) throws NPE
 */
public void testDescendingRemove2_NullPointerException() {
    try {
        ConcurrentNavigableMap c = dmap5();
        c.remove(null, "whatever");
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 18
Source File: ConcurrentSkipListSubMapJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * remove(null) throws NPE
 */
public void testDescendingRemove1_NullPointerException() {
    try {
        ConcurrentNavigableMap c = dmap5();
        c.remove(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 19
Source File: TestWrites.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test
// Validate all the commit check return codes OpenFileCtx.COMMIT_STATUS with
// large file upload option.
public void testCheckCommitLargeFileUpload() 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, true);
  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(10, 15),
      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) 8);
  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);
  
  // Test commit sequential writes
  status = ctx.checkCommitInternal(10, ch, 1, attr, false);
  Assert.assertTrue(status == COMMIT_STATUS.COMMIT_SPECIAL_WAIT);
  ret = ctx.checkCommit(dfsClient, 10, ch, 1, attr, false);
  Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_SPECIAL_WAIT);

  // Test commit non-sequential writes
  ConcurrentNavigableMap<Long, CommitCtx> commits = ctx
      .getPendingCommitsForTest();
  Assert.assertTrue(commits.size() == 1);
  ret = ctx.checkCommit(dfsClient, 16, ch, 1, attr, false);
  Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_SPECIAL_SUCCESS);
  Assert.assertTrue(commits.size() == 1);
  
  // Test request with zero commit offset
  commits.remove(new Long(10));
  // There is one pending write [10,15]
  ret = ctx.checkCommitInternal(0, ch, 1, attr, false);
  Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_SPECIAL_WAIT);
  
  ret = ctx.checkCommitInternal(9, ch, 1, attr, false);
  Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_SPECIAL_WAIT);
  Assert.assertTrue(commits.size() == 2);

  // Empty pending writes. nextOffset=10, flushed pos=8
  ctx.getPendingWritesForTest().remove(new OffsetRange(10, 15));
  ret = ctx.checkCommit(dfsClient, 0, ch, 1, attr, false);
  Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_SPECIAL_WAIT);
  
  // Empty pending writes
  ctx.setNextOffsetForTest((long) 8); // flushed pos = 8
  ret = ctx.checkCommit(dfsClient, 0, ch, 1, attr, false);
  Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_FINISHED);
  
}
 
Example 20
Source File: SeaCloudsApplicationDataStorage.java    From SeaCloudsPlatform with Apache License 2.0 4 votes vote down vote up
public SeaCloudsApplicationData removeSeaCloudsApplicationDataById(String id) {
    ConcurrentNavigableMap<String, SeaCloudsApplicationData> treeMap = dataStore.getTreeMap(SEACLOUDS_APPLICATION_DATA_COLLECTION_TAG);
    SeaCloudsApplicationData remove = treeMap.remove(id);
    dataStore.commit();
    return remove;
}