Search in sources :

Example 76 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project j2objc by google.

the class ConcurrentSkipListMapTest method testPutIfAbsent.

/**
 * putIfAbsent works when the given key is not present
 */
public void testPutIfAbsent() {
    ConcurrentSkipListMap map = map5();
    map.putIfAbsent(six, "Z");
    assertTrue(map.containsKey(six));
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 77 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project j2objc by google.

the class ConcurrentSkipListMapTest method testHeadMapContents.

/**
 * headMap returns map with keys in requested range
 */
public void testHeadMapContents() {
    ConcurrentSkipListMap map = map5();
    NavigableMap sm = map.headMap(four, false);
    assertTrue(sm.containsKey(one));
    assertTrue(sm.containsKey(two));
    assertTrue(sm.containsKey(three));
    assertFalse(sm.containsKey(four));
    assertFalse(sm.containsKey(five));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(one, k);
    k = (Integer) (i.next());
    assertEquals(two, k);
    k = (Integer) (i.next());
    assertEquals(three, k);
    assertFalse(i.hasNext());
    sm.clear();
    assertTrue(sm.isEmpty());
    assertEquals(2, map.size());
    assertEquals(four, map.firstKey());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) NavigableMap(java.util.NavigableMap) Iterator(java.util.Iterator)

Example 78 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project j2objc by google.

the class ConcurrentSkipListMapTest method testTailMapContents.

/**
 * tailMap returns map with keys in requested range
 */
public void testTailMapContents() {
    ConcurrentSkipListMap map = map5();
    NavigableMap sm = map.tailMap(two, true);
    assertFalse(sm.containsKey(one));
    assertTrue(sm.containsKey(two));
    assertTrue(sm.containsKey(three));
    assertTrue(sm.containsKey(four));
    assertTrue(sm.containsKey(five));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(two, k);
    k = (Integer) (i.next());
    assertEquals(three, k);
    k = (Integer) (i.next());
    assertEquals(four, k);
    k = (Integer) (i.next());
    assertEquals(five, k);
    assertFalse(i.hasNext());
    Iterator r = sm.descendingKeySet().iterator();
    k = (Integer) (r.next());
    assertEquals(five, k);
    k = (Integer) (r.next());
    assertEquals(four, k);
    k = (Integer) (r.next());
    assertEquals(three, k);
    k = (Integer) (r.next());
    assertEquals(two, k);
    assertFalse(r.hasNext());
    Iterator ei = sm.entrySet().iterator();
    Map.Entry e;
    e = (Map.Entry) (ei.next());
    assertEquals(two, e.getKey());
    assertEquals("B", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(three, e.getKey());
    assertEquals("C", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(four, e.getKey());
    assertEquals("D", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    assertFalse(i.hasNext());
    NavigableMap ssm = sm.tailMap(four, true);
    assertEquals(four, ssm.firstKey());
    assertEquals(five, ssm.lastKey());
    assertEquals("D", ssm.remove(four));
    assertEquals(1, ssm.size());
    assertEquals(3, sm.size());
    assertEquals(4, map.size());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) NavigableMap(java.util.NavigableMap) Iterator(java.util.Iterator) NavigableMap(java.util.NavigableMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Map(java.util.Map)

Example 79 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project j2objc by google.

the class ConcurrentSkipListMapTest method testRemove1_NullPointerException.

/**
 * remove(null) throws NPE
 */
public void testRemove1_NullPointerException() {
    ConcurrentSkipListMap c = new ConcurrentSkipListMap();
    c.put("sadsdf", "asdads");
    try {
        c.remove(null);
        shouldThrow();
    } catch (NullPointerException success) {
    }
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 80 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project j2objc by google.

the class ConcurrentSkipListMapTest method testPollLastEntry.

/**
 * pollLastEntry returns entries in order
 */
public void testPollLastEntry() {
    ConcurrentSkipListMap 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);
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) NavigableMap(java.util.NavigableMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Map(java.util.Map)

Aggregations

ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)183 Test (org.junit.Test)66 PollStatus (org.opennms.netmgt.poller.PollStatus)32 MonitoredService (org.opennms.netmgt.poller.MonitoredService)31 Map (java.util.Map)30 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)25 MqttDeviceTwin (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin)23 HashMap (java.util.HashMap)21 DeviceTwinMessage (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage)17 NavigableMap (java.util.NavigableMap)14 Set (java.util.Set)12 Iterator (java.util.Iterator)11 NavigableSet (java.util.NavigableSet)11 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)11 IOException (java.io.IOException)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 ArrayList (java.util.ArrayList)9 BitSet (java.util.BitSet)9 DeviceOperations (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations)8 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)8