Search in sources :

Example 26 with UUID

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

the class ExtendedUUIDTest method testSiteUUID.

public void testSiteUUID() throws Exception {
    UUID a = (UUID) Util.createRandomAddress("A"), b = (UUID) Util.createRandomAddress("B");
    SiteUUID sa = new SiteUUID(a, "sm-a", "sfo");
    SiteUUID sb = new SiteUUID(b, "b", "lon").put(Util.stringToBytes("id"), Util.objectToByteBuffer(322649)).setFlag(RELAY2.can_become_site_master_flag);
    System.out.println("sb = " + sb);
    assert sa.getName().equals("sm-a");
    assert sa.getSite().equals("sfo");
    SiteUUID copy = (SiteUUID) sb.copy();
    assert copy.equals(sb);
    assert copy.getName().equals(sb.getName());
    assert copy.getSite().equals(sb.getSite());
}
Also used : SiteUUID(org.jgroups.protocols.relay.SiteUUID) UUID(org.jgroups.util.UUID) SiteUUID(org.jgroups.protocols.relay.SiteUUID) ExtendedUUID(org.jgroups.util.ExtendedUUID) FlagsUUID(org.jgroups.util.FlagsUUID)

Example 27 with UUID

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

the class ExtendedUUIDTest method testPrintFunction.

public void testPrintFunction() throws IOException {
    ExtendedUUID uuid = ExtendedUUID.randomUUID("A").put("name", Util.stringToBytes("Bela"));
    Function<ExtendedUUID, String> print_func = e -> {
        byte[] val = e.get("name");
        return Util.bytesToString(val);
    };
    String output = uuid.toString();
    assert "A(name=Bela)".equals(output);
    ExtendedUUID.setPrintFunction(print_func);
    output = uuid.toString();
    assert "Bela".equals(output);
    ExtendedUUID uuid2 = ExtendedUUID.randomUUID("B").put("name", Util.stringToBytes("Sabine"));
    output = uuid2.toString();
    assert "Sabine".equals(output);
    ExtendedUUID.setPrintFunction(ExtendedUUID::print);
    System.out.printf("uuid=%s, uuid2=%s\n", uuid, uuid2);
}
Also used : UUID(org.jgroups.util.UUID) Arrays(java.util.Arrays) Util(org.jgroups.util.Util) Test(org.testng.annotations.Test) IOException(java.io.IOException) HashMap(java.util.HashMap) Function(java.util.function.Function) SiteMaster(org.jgroups.protocols.relay.SiteMaster) SiteUUID(org.jgroups.protocols.relay.SiteUUID) ExtendedUUID(org.jgroups.util.ExtendedUUID) RELAY2(org.jgroups.protocols.relay.RELAY2) Global(org.jgroups.Global) Map(java.util.Map) FlagsUUID(org.jgroups.util.FlagsUUID) ExtendedUUID(org.jgroups.util.ExtendedUUID)

Aggregations

UUID (org.jgroups.util.UUID)27 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)5 GMSMember (org.apache.geode.distributed.internal.membership.gms.GMSMember)4 Event (org.jgroups.Event)4 Test (org.junit.Test)4 SecurityTest (org.apache.geode.test.junit.categories.SecurityTest)3 UnitTest (org.apache.geode.test.junit.categories.UnitTest)3 SiteUUID (org.jgroups.protocols.relay.SiteUUID)3 IpAddress (org.jgroups.stack.IpAddress)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 NetView (org.apache.geode.distributed.internal.membership.NetView)2 ExtendedUUID (org.jgroups.util.ExtendedUUID)2 FlagsUUID (org.jgroups.util.FlagsUUID)2 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1