Package org.lilyproject.repository.impl.id

Examples of org.lilyproject.repository.impl.id.IdGeneratorImpl


        assertEquals(recordId, idGenerator.fromString(recordId.toString()));
    }

    @Test
    public void testUUID() {
        IdGenerator idGenerator = new IdGeneratorImpl();

        // Test string representation
        String uuidRecordIDString = "UUID.d27cdb6e-ae6d-11cf-96b8-444553540000";
        assertEquals(uuidRecordIDString, idGenerator.fromString(uuidRecordIDString).toString());

        // Check it's not recognized as a variant
        assertTrue(idGenerator.fromString(uuidRecordIDString).isMaster());

        // Test bytes representation
        byte[] uuidRecordIdBytes = new byte[] {1, -46, 124, -37, 110, -82, 109, 17, -49, -106, -72, 68, 69, 83, 84, 0, 0};
        assertArrayEquals(uuidRecordIdBytes, idGenerator.fromBytes(uuidRecordIdBytes).toBytes());

        assertEquals(uuidRecordIDString, idGenerator.fromBytes(uuidRecordIdBytes).toString());

    }
View Full Code Here


    }

    @Test
    public void testUSER() {
        IdGenerator idGenerator = new IdGeneratorImpl();
        RecordId newRecordId = idGenerator.newRecordId("aUserId");
        String userRecordIDString = "USER.aUserId";

        // Check it's not recognized as a variant
        assertTrue(newRecordId.isMaster());

        // Test string representation
        assertEquals(newRecordId, idGenerator.fromString(userRecordIDString));
        assertEquals(userRecordIDString, idGenerator.fromString(userRecordIDString).toString());

        // Test bytes representation cycle
        byte[] userRecordIdBytes = newRecordId.toBytes();
        assertArrayEquals(userRecordIdBytes, idGenerator.fromBytes(userRecordIdBytes).toBytes());

        assertEquals(userRecordIDString, idGenerator.fromBytes(userRecordIdBytes).toString());

        // Test the bytes representation is really what we expect it to be
        byte[] idBytes = new byte[] {0, 65, 66, 67};
        String idString = "USER.ABC";
        assertArrayEquals(idBytes, idGenerator.fromString(idString).toBytes());


        byte[] withDotsBytes = new byte[] { 0, 65, 66, ':', 67, 68, '.', 69, 70 };
        String withDots = "USER.AB:CD\\.EF";
        assertArrayEquals(withDotsBytes, idGenerator.fromString(withDots).toBytes());
    }
View Full Code Here

        assertArrayEquals(withDotsBytes, idGenerator.fromString(withDots).toBytes());
    }

    @Test
    public void testUUIDWithVariantSingleProperty() {
        IdGenerator idGenerator = new IdGeneratorImpl();
        RecordId masterRecordId = idGenerator.newRecordId();
        Map<String, String> variantProperties = new HashMap<String, String>();
        variantProperties.put("dim1", "dimvalue1");
        RecordId variantRecordId = idGenerator.newRecordId(masterRecordId, variantProperties);

        // Test it is recognized as variant
        assertFalse(variantRecordId.isMaster());

        // Test string representation is what it is supposed to be
        String variantRecordIdString = masterRecordId.toString() + ".dim1=dimvalue1";
        assertEquals(variantRecordIdString, variantRecordId.toString());
        assertEquals(variantRecordId, idGenerator.fromString(variantRecordIdString));

        // Test round-trip string & bytes conversion
        assertEquals(variantRecordId, idGenerator.fromString(variantRecordId.toString()));
        assertEquals(variantRecordId, idGenerator.fromBytes(variantRecordId.toBytes()));

        // Test bytes representation is really what we expect it to be
        byte[] masterIdBytes = new byte[] {
                /* uuid type marker */1,
                /* uuid bytes */-46, 124, -37, 110, -82, 109, 17, -49, -106, -72, 68, 69, 83, 84, 0, 0 };

        byte[] variantIdBytes = new byte[] {
                /* uuid type marker */1,
                /* uuid bytes */-46, 124, -37, 110, -82, 109, 17, -49, -106, -72, 68, 69, 83, 84, 0, 0
                /* length of key (vint) */, 1
                /* the key (letter X) */, 88
                /* length of value (vint) */, 3
                /* the value (ABC) */, 65, 66, 67 };

        RecordId variantId = idGenerator.newRecordId(idGenerator.fromBytes(masterIdBytes),
                Collections.singletonMap("X", "ABC"));
        assertArrayEquals(variantIdBytes, variantId.toBytes());
    }
View Full Code Here

        assertArrayEquals(variantIdBytes, variantId.toBytes());
    }

    @Test
    public void testUUUIDWithMultipleProperties() {
        IdGenerator idGenerator = new IdGeneratorImpl();
        RecordId masterRecordId = idGenerator.newRecordId();
        Map<String, String> variantProperties = new HashMap<String, String>();
        variantProperties.put("dim1", "dimvalue1");
        variantProperties.put("dim2", "dimvalue2");

        RecordId variantRecordId = idGenerator.newRecordId(masterRecordId, variantProperties);

        // Test string representation is what it is supposed to be
        String variantRecordIdString = masterRecordId.toString() + ".dim1=dimvalue1,dim2=dimvalue2";
        assertEquals(variantRecordIdString, variantRecordId.toString());
        assertEquals(variantRecordId, idGenerator.fromString(variantRecordIdString));

        // Test round-trip string & bytes conversion
        assertEquals(variantRecordId, idGenerator.fromString(variantRecordIdString));
        assertEquals(variantRecordId, idGenerator.fromBytes(variantRecordId.toBytes()));
    }
View Full Code Here

        assertEquals(variantRecordId, idGenerator.fromBytes(variantRecordId.toBytes()));
    }

    @Test
    public void testUserIdWithVariantProperties() {
        IdGenerator idGenerator = new IdGeneratorImpl();
        RecordId masterId = idGenerator.newRecordId("marvellous");
        Map<String, String> variantProperties = new HashMap<String, String>();
        variantProperties.put("a", "x");
        variantProperties.put("aa", "xx");

        RecordId variantId = idGenerator.newRecordId(masterId, variantProperties);

        // Test it is recognized as variant
        assertFalse(variantId.isMaster());

        // Test round-trip string & bytes conversion
        assertEquals(variantId, idGenerator.fromBytes(variantId.toBytes()));
        assertEquals(variantId, idGenerator.fromString(variantId.toString()));

        // Test string representation is what it is supposed to be
        String expectedString = "USER.marvellous.a=x,aa=xx";
        assertEquals(expectedString, variantId.toString());
View Full Code Here

        assertArrayEquals(variantIdBytes, variantId.toBytes());
    }

    @Test
    public void testNullCharacterNotAllowedInUserId() {
        IdGenerator idGenerator = new IdGeneratorImpl();
        try {
            idGenerator.fromString("USER.hello\u0000world");
            fail("Expected an exception when using zero byte in string.");
        } catch (IllegalArgumentException e) {
            // expected
        }
        try {
            idGenerator.newRecordId("hello\u0000world");
            fail("Expected an exception when using zero byte in string.");
        } catch (IllegalArgumentException e) {
            // expected
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testReservedCharacterEscapingInUserId() {
        IdGenerator idGenerator = new IdGeneratorImpl();
        char[] chars = new char[] {'.', ',', '=' };
        for (char c : chars) {
            RecordId recordId = idGenerator.newRecordId("hello" + c + "world");

            String idString = recordId.toString();
            assertEquals("USER.hello\\" + c + "world", idString);
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testReservedCharacterUnEscapingInUserId() {
        IdGenerator idGenerator = new IdGeneratorImpl();
        String idString = "USER.special\\.characters\\,are\\=fun\\\\.key=hoeba\\=hoep";
        RecordId recordId = idGenerator.fromString(idString);
        String encodedString = recordId.toString();

        assertEquals(idString, encodedString);
    }
View Full Code Here

            testEscapedNotAllowedChar(c);
        }
    }

    private void testNotAllowedChar(char c) {
        IdGenerator idGenerator = new IdGeneratorImpl();
        try {
            idGenerator.fromString("USER.hello" + c + "world");
            fail("Expected an exception when using character " + c);
        } catch (IllegalArgumentException e) {
            // expected
        }
    }
View Full Code Here

            // expected
        }
    }

    private void testEscapedNotAllowedChar(char c) {
        IdGenerator idGenerator = new IdGeneratorImpl();
        String idString = "USER.hello\\" + c + "world";
        try {
            RecordId recordId = idGenerator.fromString(idString);
            assertEquals(idString, recordId.toString());
        } catch (IllegalArgumentException e) {
            // expected
        }
    }
View Full Code Here

TOP

Related Classes of org.lilyproject.repository.impl.id.IdGeneratorImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.