Package org.lilyproject.repository.impl.id

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


import static org.mockito.Mockito.when;

public class FieldValueStringConverterTest {
    @Test
    public void testFromString() throws Exception {
        IdGenerator idGenerator = new IdGeneratorImpl();

        ValueType valueType = mock(ValueType.class);

        when(valueType.getBaseName()).thenReturn("STRING");
        assertEquals("foo", FieldValueStringConverter.fromString("foo", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("INTEGER");
        assertEquals(new Integer(123), FieldValueStringConverter.fromString("123", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("LONG");
        assertEquals(new Long(12345), FieldValueStringConverter.fromString("12345", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("DOUBLE");
        assertEquals(new Double(12345.6), FieldValueStringConverter.fromString("12345.6", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("DECIMAL");
        assertEquals(new BigDecimal("12345.12345"), FieldValueStringConverter.fromString("12345.12345", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("URI");
        assertEquals(new URI("http://www.ngdata.com/"),
                FieldValueStringConverter.fromString("http://www.ngdata.com/", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("BOOLEAN");
        assertEquals(Boolean.TRUE, FieldValueStringConverter.fromString("true", valueType, idGenerator));
        assertEquals(Boolean.FALSE, FieldValueStringConverter.fromString("false", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("LINK");
        assertEquals(new Link(idGenerator.newRecordId("foobar")),
                FieldValueStringConverter.fromString("USER.foobar", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("DATE");
        assertEquals(new LocalDate(2012, 6, 28), FieldValueStringConverter.fromString("2012-06-28", valueType, idGenerator));
View Full Code Here


    private IdGenerator idGenerator;

    @Before
    public void setUp() {
        this.idGenerator = new IdGeneratorImpl();
    }
View Full Code Here

import static org.junit.Assert.assertTrue;

public class RecordIdWritableTest {
    @Test
    public void testComparisons() throws Exception {
        IdGenerator idGenerator = new IdGeneratorImpl();

        RecordIdWritable writable1 = new RecordIdWritable();
        RecordIdWritable writable2 = new RecordIdWritable();

        writable1.setRecordId(idGenerator.newRecordId("b"));
        writable2.setRecordId(idGenerator.newRecordId("b"));
        assertTrue(writable1.compareTo(writable2) == 0);

        writable2.setRecordId(idGenerator.newRecordId("c"));
        assertTrue(writable1.compareTo(writable2) < 0);

        writable2.setRecordId(idGenerator.newRecordId("a"));
        assertTrue(writable1.compareTo(writable2) > 0);

    }
View Full Code Here

    }

    @Test
    public void testSerializationRoundTrip() throws Exception {
        IdGenerator idGenerator = new IdGeneratorImpl();

        RecordIdWritable writable1 = new RecordIdWritable(idGenerator.newRecordId("foo"));

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DataOutput out = new DataOutputStream(bos);
        writable1.write(out);

        System.out.println(Bytes.toStringBinary(bos.toByteArray()));

        // Verify the binary length
        assertEquals(1 /* vint length */ + 1 /* record id type byte */ + "foo".length(), bos.toByteArray().length);

        RecordIdWritable writable2 = new RecordIdWritable();
        writable2.readFields(new DataInputStream(new ByteArrayInputStream(bos.toByteArray())));

        assertEquals(idGenerator.newRecordId("foo"), writable2.getRecordId());
    }
View Full Code Here

    @Test
    public void testRecordIdListMapping() throws Exception {
        byte[] mapping1Data = IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream(BASE_PATH + "shardingconfig1.json"));
        ShardSelector selector = JsonShardSelectorBuilder.build(mapping1Data);

        IdGenerator idGenerator = new IdGeneratorImpl();

        String shardName = selector.getShard(idGenerator.newRecordId());
        assertNotNull(shardName);
    }
View Full Code Here

    @Test
    public void testStringFieldListMapping() throws Exception {
        byte[] mappingData = IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream(BASE_PATH + "shardingconfig2.json"));
        ShardSelector selector = JsonShardSelectorBuilder.build(mappingData);

        IdGenerator idGenerator = new IdGeneratorImpl();
        RecordId recordId = idGenerator.newRecordId(Collections.singletonMap("transport", "car"));

        String shardName = selector.getShard(recordId);
        assertEquals("shard1", shardName);
    }
View Full Code Here

    @Test
    public void testLongFieldRangeMapping() throws Exception {
        byte[] mappingData = IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream(BASE_PATH + "shardingconfig3.json"));
        ShardSelector selector = JsonShardSelectorBuilder.build(mappingData);

        IdGenerator idGenerator = new IdGeneratorImpl();
        RecordId recordId = idGenerator.newRecordId(Collections.singletonMap("weight", "400"));

        String shardName = selector.getShard(recordId);
        assertEquals("shard1", shardName);

        recordId = idGenerator.newRecordId(Collections.singletonMap("weight", "1000"));
        shardName = selector.getShard(recordId);
        assertEquals("shard2", shardName);

        recordId = idGenerator.newRecordId(Collections.singletonMap("weight", "1200"));
        shardName = selector.getShard(recordId);
        assertEquals("shard2", shardName);

        recordId = idGenerator.newRecordId(Collections.singletonMap("weight", "341234123"));
        shardName = selector.getShard(recordId);
        assertEquals("shard3", shardName);

        recordId = idGenerator.newRecordId(Collections.singletonMap("weight", "abc"));
        try {
            shardName = selector.getShard(recordId);
            fail("Expected an exception");
        } catch (ShardSelectorException e) {
            // expected
View Full Code Here

        shards.put("shard2", "http://solr2");
        shards.put("shard3", "http://solr3");

        ShardSelector selector = DefaultShardSelectorBuilder.createDefaultSelector(shards);

        IdGenerator idGenerator = new IdGeneratorImpl();

        boolean shard1Used = false;
        boolean shard2Used = false;
        boolean shard3Used = false;

        for (int i = 0; i < 50; i++) {
            String shardName = selector.getShard(idGenerator.newRecordId());
            assertTrue(shards.containsKey(shardName));

            if (shardName.equals("shard1")) {
                shard1Used = true;
            } else if (shardName.equals("shard2")) {
View Full Code Here

    private LRepository repository;

    @Before
    public void setUp() {
        typeManager = mock(TypeManager.class, Mockito.RETURNS_DEEP_STUBS);
        idGenerator = new IdGeneratorImpl();
        repository = mock(LRepository.class);
        when(repository.getTypeManager()).thenReturn(typeManager);
        when(repository.getIdGenerator()).thenReturn(idGenerator);
    }
View Full Code Here

    public static void setUpBeforeClass() throws Exception {
        TestHelper.setupLogging();
        HBASE_PROXY = new HBaseProxy();
        HBASE_PROXY.start();

        IdGenerator idGenerator = new IdGeneratorImpl();
        configuration = HBASE_PROXY.getConf();
        zooKeeper = new StateWatchingZooKeeper(HBASE_PROXY.getZkConnectString(), 10000);
        hbaseTableFactory = new HBaseTableFactoryImpl(HBASE_PROXY.getConf());

        RepositoryModel repositoryModel = new RepositoryModelImpl(zooKeeper);
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.