Search in sources :

Example 6 with ExtendedUUID

use of org.jgroups.util.ExtendedUUID in project JGroups by belaban.

the class ExtendedUUIDTest method testFlags.

public void testFlags() {
    ExtendedUUID uuid = ExtendedUUID.randomUUID("A").setFlag(RELAY2.site_master_flag).setFlag((short) 2).setFlag((short) 4);
    System.out.println("uuid = " + uuid);
    assert uuid.isFlagSet(RELAY2.site_master_flag);
    assert uuid.isFlagSet((short) 2);
    assert uuid.isFlagSet((short) 4);
    uuid.clearFlag((short) 2);
    assert !uuid.isFlagSet((short) 2);
}
Also used : ExtendedUUID(org.jgroups.util.ExtendedUUID)

Example 7 with ExtendedUUID

use of org.jgroups.util.ExtendedUUID in project JGroups by belaban.

the class ExtendedUUIDTest method testAddContents.

public void testAddContents() throws Exception {
    ExtendedUUID a = ExtendedUUID.randomUUID("A").setFlag((short) 1);
    a.put("name", Util.stringToBytes("Bela")).put("age", Util.objectToByteBuffer(49)).put("bool", Util.objectToByteBuffer(true));
    ExtendedUUID b = ExtendedUUID.randomUUID("B").setFlag((short) 2).setFlag((short) 4);
    b.put("one", null).put("two", Util.stringToBytes("two")).put("name", Util.stringToBytes("Michelle"));
    a.addContents(b);
    for (short flag : Arrays.asList((short) 1, (short) 2, (short) 4)) assert a.isFlagSet(flag);
    for (String key : Arrays.asList("name", "age", "bool", "one", "two")) assert a.keyExists(key);
    assert Util.bytesToString(a.get("two")).equals("two");
    assert Util.bytesToString(a.get("name")).equals("Bela");
}
Also used : ExtendedUUID(org.jgroups.util.ExtendedUUID)

Example 8 with ExtendedUUID

use of org.jgroups.util.ExtendedUUID in project JGroups by belaban.

the class ExtendedUUIDTest method testResizeBeyond255.

public void testResizeBeyond255() throws Exception {
    ExtendedUUID uuid = ExtendedUUID.randomUUID("A");
    byte[] val = Util.objectToByteBuffer("tmp");
    for (int i = 1; i <= 0xff; i++) uuid.put(String.valueOf(i), val);
    try {
        uuid.put(String.valueOf(256), val);
        assert false : " should have thrown an exception";
    } catch (ArrayIndexOutOfBoundsException ex) {
        System.out.println("got exception as expected: " + ex);
    }
}
Also used : ExtendedUUID(org.jgroups.util.ExtendedUUID)

Example 9 with ExtendedUUID

use of org.jgroups.util.ExtendedUUID in project JGroups by belaban.

the class ExtendedUUIDTest method testMarshallingWithRemoval.

public void testMarshallingWithRemoval() throws Exception {
    ExtendedUUID uuid = ExtendedUUID.randomUUID("A");
    byte[] value = Util.objectToByteBuffer("Bela");
    for (int i = 1; i <= 10; i++) uuid.put(String.valueOf(i), value);
    assert uuid.length() == 10;
    for (int i = 1; i <= 10; i++) if (i % 2 == 0)
        uuid.remove(String.valueOf(i));
    assert uuid.length() == 5;
    int size = uuid.serializedSize();
    byte[] buffer = Util.streamableToByteBuffer(uuid);
    assert size == buffer.length : "expected size of " + size + ", but got " + buffer.length;
    ExtendedUUID uuid2 = Util.streamableFromByteBuffer(ExtendedUUID::new, buffer);
    assert uuid2.length() == 5;
    for (int i = 1; i <= 10; i++) {
        boolean exists = i % 2 != 0;
        assert uuid2.keyExists(String.valueOf(i)) == exists;
    }
}
Also used : ExtendedUUID(org.jgroups.util.ExtendedUUID)

Example 10 with ExtendedUUID

use of org.jgroups.util.ExtendedUUID in project JGroups by belaban.

the class ExtendedUUIDTest method testCopy.

public void testCopy() throws Exception {
    ExtendedUUID uuid = ExtendedUUID.randomUUID("A").setFlag((short) 16).setFlag((short) 32);
    uuid.put("name", Util.objectToByteBuffer("Bela")).put("age", Util.objectToByteBuffer(49)).put("bool", Util.objectToByteBuffer(true));
    ExtendedUUID uuid2 = new ExtendedUUID(uuid);
    assert uuid.getMostSignificantBits() == uuid2.getMostSignificantBits();
    assert uuid.getLeastSignificantBits() == uuid2.getLeastSignificantBits();
    assert uuid2.isFlagSet((short) 16) && uuid2.isFlagSet((short) 32);
    assert uuid2.length() == 3;
    for (String key : Arrays.asList("name", "age", "bool")) assert uuid2.keyExists(key);
}
Also used : ExtendedUUID(org.jgroups.util.ExtendedUUID)

Aggregations

ExtendedUUID (org.jgroups.util.ExtendedUUID)14