コード例 #1
0
  @Test
  public void testAcquireAndGet()
      throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException {
    int entries = 1000 * 1000;
    SharedHashMap<CharSequence, LongValue> map = getSharedMap(entries, 128, 24);

    LongValue value = new LongValueNative();
    LongValue value2 = new LongValueNative();
    LongValue value3 = new LongValueNative();

    for (int j = 1; j <= 3; j++) {
      for (int i = 0; i < entries; i++) {
        CharSequence userCS = getUserCharSequence(i);

        if (j > 1) {
          assertNotNull(map.getUsing(userCS, value));
        } else {
          map.acquireUsing(userCS, value);
        }
        assertEquals(j - 1, value.getValue());

        value.addAtomicValue(1);

        assertEquals(value2, map.acquireUsing(userCS, value2));
        assertEquals(j, value2.getValue());

        assertEquals(value3, map.getUsing(userCS, value3));
        assertEquals(j, value3.getValue());
      }
    }

    map.close();
  }
コード例 #2
0
  @Test
  public void testPutAndRemove()
      throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException {
    String TMP = System.getProperty("java.io.tmpdir");
    File file = new File(TMP + "/shm-remove-test");
    file.delete();
    file.deleteOnExit();
    int entries = 100 * 1000;
    SharedHashMap<CharSequence, CharSequence> map =
        new SharedHashMapBuilder()
            .entries(entries)
            .minSegments(16)
            .entrySize(32)
            .putReturnsNull(true)
            .removeReturnsNull(true)
            .create(file, CharSequence.class, CharSequence.class);
    StringBuilder key = new StringBuilder();
    StringBuilder value = new StringBuilder();
    StringBuilder value2 = new StringBuilder();
    for (int j = 1; j <= 3; j++) {
      for (int i = 0; i < entries; i++) {
        key.setLength(0);
        key.append("user:"******"value:").append(i);
        //                System.out.println(key);
        assertNull(map.getUsing(key, value));
        assertNull(map.put(key, value));
        assertNotNull(map.getUsing(key, value2));
        assertEquals(value.toString(), value2.toString());
        assertNull(map.remove(key));
        assertNull(map.getUsing(key, value));
      }
    }

    map.close();
  }
コード例 #3
0
 @Test
 public void testGetWithNullContainer() throws Exception {
   SharedHashMap<CharSequence, LongValue> map = getSharedMap(10 * 1000, 128, 24);
   map.acquireUsing("key", new LongValueNative());
   assertEquals(0, map.getUsing("key", null).getValue());
 }
コード例 #4
0
 @Test
 public void testGetWithoutAcquireFirst() throws Exception {
   SharedHashMap<CharSequence, LongValue> map = getSharedMap(10 * 1000, 128, 24);
   assertNull(map.getUsing("key", new LongValueNative()));
 }
コード例 #5
0
 @Test
 public void testGetWithNullKey() throws Exception {
   SharedHashMap<CharSequence, LongValue> map = getSharedMap(10 * 1000, 128, 24);
   assertNull(map.getUsing(null, new LongValueNative()));
 }