Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.TypeManager



    @Test
    public void testDisableRefresh() throws Exception {
        String namespace = "testDisableRefresh";
        TypeManager typeManager = repoSetup.getTypeManager();
        TypeManager typeManager2 = repoSetup.getNewTypeManager();
        typeManagersToClose.add(typeManager2);

        // Disable the cache refreshing
        typeManager.disableSchemaCacheRefresh();

        // Give all type managers time to notice the disabling
        Thread.sleep(1000);

        // Check all type managers have the refreshing disabled
        Assert.assertFalse(typeManager2.isSchemaCacheRefreshEnabled());
        Assert.assertFalse(typeManager.isSchemaCacheRefreshEnabled());

        RecordType recordType1 = typeManager.recordTypeBuilder().defaultNamespace(namespace).name("recordType1")
                .fieldEntry().defineField().name("type1").create().add().create();

        try {
            typeManager2.getRecordTypeByName(new QName(namespace, "recordType1"), null);
            Assert
                    .fail("Did not expect typeManager2 to contain the record type since the cache refreshing is disabled");
        } catch (RecordTypeNotFoundException expected) {
        }

        // Force a cache refresh
        typeManager.triggerSchemaCacheRefresh();

        Assert.assertEquals(recordType1, waitForRecordType(5000, new QName(namespace, "recordType1"), typeManager2));

        RecordType recordType2 = typeManager.recordTypeBuilder().defaultNamespace(namespace).name("recordType2")
                .fieldEntry().defineField().name("type2").create().add().create();

        typeManager.enableSchemaCacheRefresh();

        // Give all type managers time to notice the enabling
        Thread.sleep(1000);

        // Check all type managers have the refreshing enabled
        Assert.assertTrue(typeManager2.isSchemaCacheRefreshEnabled());
        Assert.assertTrue(typeManager.isSchemaCacheRefreshEnabled());

        // Assert that the record type created before enabling the cache
        // refreshing
        // is now seen. i.e. the cache of typeManager2 is refreshed
View Full Code Here


    // This test is introduced to do some profiling
    @Ignore
    @Test
    public void testManyTypes() throws Exception {
        String namespace = "testManyTypesSameCache";
        TypeManager typeManager = repoSetup.getTypeManager();

        // Add some extra type managers to simulate multiple caches that need to
        // be refreshed
        for (int i = 0; i < 10; i++) {
            typeManagersToClose.add(repoSetup.getNewTypeManager());
        }

        long total = 0;
        int iterations = 10;
        int nrOfTypes = 100; // Set to a low number to reduce automated test
        // time
        for (int i = 0; i < iterations; i++) {
            long before = System.currentTimeMillis();
            for (int j = 0; j < nrOfTypes; j++) {
                typeManager.recordTypeBuilder().defaultNamespace(namespace).name("recordType" + (i * nrOfTypes + j))
                        .fieldEntry().defineField().name("fieldType" + (i * nrOfTypes + j)).create().add().create();
            }
            long duration = (System.currentTimeMillis() - before);
            total += duration;
            System.out.println(i + " :Creating " + nrOfTypes + " record types and " + nrOfTypes + " field types took: "
                    + duration);
            // if (i == 5)
            // newTypeManager.close();
        }
        System.out.println("Creating " + (iterations * nrOfTypes) + " record types and " + (iterations * nrOfTypes)
                + " field types took: " + total);

        // Make sure all types are known by the typeManager
        for (int i = 0; i < iterations * nrOfTypes; i++) {
            typeManager.getFieldTypeByName(new QName(namespace, "fieldType" + i));
            typeManager.getRecordTypeByName(new QName(namespace, "recordType" + i), null);
        }

        long before = System.currentTimeMillis();
        for (int i = 0; i < 5; i++) {
            typeManager.recordTypeBuilder().defaultNamespace(namespace).name("extraRecordType" + i).fieldEntry()
                    .defineField().name("extraFieldType" + i).create().add().create();
        }
        System.out.println("Creating 5 extra record types and 5 extra field types took: "
                + (System.currentTimeMillis() - before));

View Full Code Here

        }
    }

    @Test
    public void testRenameFieldType() throws Exception {
        TypeManager typeManager = repoSetup.getTypeManager();
        QName ftName = new QName("testRenameFieldType", "f");
        FieldType fieldType = typeManager.fieldTypeBuilder().name(ftName).create();
        for (int i = 0; i < 100; i++) {
            QName newFtName = new QName("testRenameFieldType", "f" + i);
            fieldType.setName(newFtName);
            fieldType = typeManager.updateFieldType(fieldType);
            typeManager.getFieldTypeByName(newFtName);
            ftName = newFtName;
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testRenameRecordType() throws Exception {
        TypeManager typeManager = repoSetup.getTypeManager();
        QName rtName = new QName("testRenameRecordType", "r");
        RecordType recordType = typeManager.recordTypeBuilder().name(rtName).create();
        for (int i = 0; i < 100; i++) {
            QName newRtName = new QName("testRenameRecordType", "r" + i);
            recordType.setName(newRtName);
            recordType = typeManager.updateRecordType(recordType);
            typeManager.getRecordTypeByName(newRtName, null);
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testRecordTypeInCacheDoesNotChange() throws Exception {
        TypeManager typeManager = repoSetup.getTypeManager();
        FieldType fieldType = typeManager.fieldTypeBuilder().name("testRecordTypeInCacheDoesNotChange", "f").create();
        QName rtName = new QName("testRecordTypeInCacheDoesNotChange", "r");
        RecordType recordType = typeManager.recordTypeBuilder().name(rtName).create();
        Assert.assertNull(typeManager.getRecordTypeByName(rtName, null).getFieldTypeEntry(fieldType.getId()));
        recordType.addFieldTypeEntry(fieldType.getId(), true);
        Assert.assertNull(typeManager.getRecordTypeByName(rtName, null).getFieldTypeEntry(fieldType.getId()));
    }
View Full Code Here

        repoSetup.setupRepository();

        repository = repoSetup.getRepositoryManager().getDefaultRepository();
        table = repository.getDefaultTable();

        TypeManager typeManager = repository.getTypeManager();
        typeManager.createFieldType("STRING", new QName("ns", "stringField"), Scope.NON_VERSIONED);
        typeManager.createFieldType("LIST<STRING>", new QName("ns", "stringListField"), Scope.NON_VERSIONED);
        typeManager.createFieldType("LONG", new QName("ns", "longField"), Scope.NON_VERSIONED);
        typeManager.recordTypeBuilder()
                .defaultNamespace("ns")
                .name("rt")
                .fieldEntry()
                .name("stringField")
                .add()
View Full Code Here

        Assert.assertEquals("myvalue", doc.get("a_string").getValue());
    }


    public Result encodeRecord(Record record) throws InterruptedException, RepositoryException {
        TypeManager typeManager = repositoryManager.getDefaultRepository().getTypeManager();
        List<KeyValue> kvs = Lists.newArrayList();

        RecordEvent event = new RecordEvent();
        event.setType(RecordEvent.Type.CREATE);
        event.setTableName(LilyHBaseSchema.Table.RECORD.name);
        event.setVersionCreated(record.getVersion());

        byte[] rowKey = record.getId().toBytes();
        byte[] family = LilyHBaseSchema.RecordCf.DATA.bytes;

        kvs.add(new KeyValue(rowKey, family, LilyHBaseSchema.RecordColumn.VERSION.bytes, 1L, Bytes.toBytes(record.getVersion())));

        kvs.add(new KeyValue(rowKey, family, LilyHBaseSchema.RecordColumn.NON_VERSIONED_RT_ID.bytes,
                1L, typeManager.getRecordTypeByName(record.getRecordTypeName(Scope.NON_VERSIONED),
                        record.getRecordTypeVersion(Scope.NON_VERSIONED)).getId().getBytes()));
        kvs.add(new KeyValue(rowKey, family, LilyHBaseSchema.RecordColumn.NON_VERSIONED_RT_VERSION.bytes,
                1L, Bytes.toBytes(record.getRecordTypeVersion(Scope.NON_VERSIONED))));
        /*
        kvs.add(new KeyValue(rowKey, family, LilyHBaseSchema.RecordColumn.VERSIONED_RT_ID.bytes,
                typeManager.getRecordTypeByName(record.getRecordTypeName(Scope.VERSIONED),
                        record.getRecordTypeVersion(Scope.VERSIONED)).getId().getBytes()));
        kvs.add(new KeyValue(rowKey, family, LilyHBaseSchema.RecordColumn.VERSIONED_RT_VERSION.bytes,
                Bytes.toBytes(record.getRecordTypeVersion(Scope.VERSIONED))));

        kvs.add(new KeyValue(rowKey, family, LilyHBaseSchema.RecordColumn.VERSIONED_MUTABLE_RT_ID.bytes,
                typeManager.getRecordTypeByName(record.getRecordTypeName(Scope.VERSIONED_MUTABLE),
                        record.getRecordTypeVersion(Scope.VERSIONED_MUTABLE)).getId().getBytes()));
        kvs.add(new KeyValue(rowKey, family, LilyHBaseSchema.RecordColumn.NON_VERSIONED_RT_VERSION.bytes,
                Bytes.toBytes(record.getRecordTypeVersion(Scope.VERSIONED_MUTABLE))));
                */

        for (QName fieldName : record.getFields().keySet()) {
            FieldType fieldType = typeManager.getFieldTypeByName(fieldName);
            Metadata metadata = record.getMetadata(fieldName);
            boolean hasMetadata = metadata != null && !metadata.getMap().isEmpty();

            DataOutput output = new DataOutputImpl();

View Full Code Here

TOP

Related Classes of org.lilyproject.repository.api.TypeManager

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.