Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.Repository


        }

        @Override
        public LTable getTable(String tableName) throws InterruptedException, RepositoryException {
            if (!tableCache.containsKey(tableName)) {
                Repository repository = (Repository) delegate.getTable(tableName);
                TrackingTable trackingTable = new TrackingTable(repository, this);
                tableCache.put(tableName, trackingTable);
            }
            return tableCache.get(tableName);
        }
View Full Code Here


    @Before
    public void setUp() throws IOException, InterruptedException, RepositoryException {
        RepositoryManager repositoryManager = mock(RepositoryManager.class);
        table = mock(LTable.class);
        Repository repository = mock(Repository.class);
        this.repository = repository;
        when(repository.getTable(Table.RECORD.name)).thenReturn(table);
        when(repositoryManager.getRepository(repositoryName)).thenReturn(repository);
        TypeManager typeManager = mock(TypeManager.class);
        avroConverter = mock(AvroConverter.class);
        avroLilyImpl = new AvroLilyImpl(repositoryManager, typeManager);
        avroLilyImpl.setAvroConverter(avroConverter);
View Full Code Here

    @Test
    public void test() throws Exception {
        LilyClient client = lilyProxy.getLilyServerProxy().getClient();

        // Obtain a repository
        Repository repository = client.getRepository();

        TypeManager typeMgr = repository.getTypeManager();

        QName fieldName = new QName("ns", "f1");
        FieldType fieldType = typeMgr.newFieldType(typeMgr.getValueType("STRING"), fieldName, Scope.NON_VERSIONED);
        fieldType = typeMgr.createFieldType(fieldType);

        QName typeName = new QName("ns", "rt1");
        RecordType recordType = typeMgr.newRecordType(typeName);
        recordType.addFieldTypeEntry(fieldType.getId(), false);
        recordType = typeMgr.createRecordType(recordType);

        Record record = repository.newRecord();
        record.setRecordType(typeName);
        record.setField(fieldName, "foo");
        record = repository.create(record);

        assertEquals("foo-create-hook", record.getField(fieldName));

        record = repository.read(record.getId());
        assertEquals("foo-create-hook", record.getField(fieldName));

        record.setField(fieldName, "bar");
        record = repository.update(record);

        assertEquals("bar-update-hook", record.getField(fieldName));

        record = repository.read(record.getId());
        assertEquals("bar-update-hook", record.getField(fieldName));
    }
View Full Code Here

        LilyClient client = lilyProxy.getLilyServerProxy().getClient();

        //
        // Create some records
        //
        Repository repository = client.getRepository();
        TypeManager typeManager = repository.getTypeManager();
        IdGenerator idGenerator = repository.getIdGenerator();

        FieldType ft1 = typeManager.createFieldType("STRING", new QName("test", "field1"), Scope.NON_VERSIONED);
        FieldType ft2 = typeManager.createFieldType("LINK", new QName("test", "field2"), Scope.NON_VERSIONED);

        RecordType rt1 = typeManager.recordTypeBuilder()
                .defaultNamespace("test")
                .name("rt1")
                .fieldEntry().use(ft1).add()
                .fieldEntry().use(ft2).add()
                .create();

        for (int i = 0; i < 300; i++) {
            repository.recordBuilder()
                    .recordType(rt1.getName())
                    .field(ft1.getName(), "foo bar bar")
                    .field(ft2.getName(), new Link(idGenerator.newRecordId()))
                    .create();
        }
View Full Code Here

     * the same LilyClient instance, the schema cache in the local client is emptied.
     */
    @Test
    public void testSchemaCacheEmptyAfterResetLilyState() throws Exception {
        LilyClient lilyClient = new LilyClient(System.getProperty("zkConn", "localhost:2181"), 20000);
        Repository repository = lilyClient.getRepository();


        for (int i = 0; i < 2; i++) {
            resetLilyState();

            // Just call a dummy method to wait for the repository to become available
            repository.newRecord();

            // Give caches some time to notice the changes going on
            Thread.sleep(2000);

            // Check that the field type and record type caches are empty
            assertEquals(0, repository.getTypeManager().getRecordTypes().size());
            assertEquals(0, repository.getTypeManager().getRecordTypesWithoutCache().size());

            // There's always the last vtag field type defined
            assertEquals(1, repository.getTypeManager().getFieldTypes().size());
            assertEquals(1, repository.getTypeManager().getFieldTypesWithoutCache().size());

            // Load a schema
            InputStream is = ResetLilyStateTest.class.getResourceAsStream("schema.json");
            JsonImport.loadSchema(repository, is);
            is.close();

            // Create a record to assure the schema we just created is in the cache.
            // If the cache would not have been cleared correctly (which is ruled out already
            // by the above assertions), then record creation might fail because it uses the
            // schema IDs of the types from the previous run.
            repository.recordBuilder()
                    .defaultNamespace("com.mycompany")
                    .recordType("Type1")
                    .field("field1", "foo")
                    .create();
        }
View Full Code Here

     */
    @Test
    public void testSchemaCacheRefreshingAfterResetLilyState() throws Exception {
        // Create two LilyClient's: each will have its own schema cache
        LilyClient lilyClient1 = new LilyClient(System.getProperty("zkConn", "localhost:2181"), 20000);
        Repository repository1 = lilyClient1.getRepository();

        LilyClient lilyClient2 = new LilyClient(System.getProperty("zkConn", "localhost:2181"), 20000);
        Repository repository2 = lilyClient2.getRepository();

        resetLilyState();

        // After resetLilyState, there should be no types
        assertEquals(0, repository2.getTypeManager().getRecordTypes().size());

        // Create schema via client 1
        InputStream is = ResetLilyStateTest.class.getResourceAsStream("schema.json");
        JsonImport.loadSchema(repository1, is);
        is.close();

        // Give client 2 just a bit of time to refresh its cache
        Thread.sleep(2000);

        // Check client 2 knows the type know
        assertEquals(1, repository2.getTypeManager().getRecordTypes().size());

        lilyClient1.close();
        lilyClient2.close();
    }
View Full Code Here

    @Test
    public void testBlob() throws Exception {
        LilyClient client = lilyProxy.getLilyServerProxy().getClient();

        // Obtain a repository
        Repository repository = client.getRepository();

        String NS = "org.lilyproject.client.test";

        // Create a blob field type and record type
        TypeManager typeManager = repository.getTypeManager();
        ValueType blobType = typeManager.getValueType("BLOB");
        FieldType blobFieldType = typeManager.newFieldType(blobType, new QName(NS, "data"), Scope.VERSIONED);
        blobFieldType = typeManager.createFieldType(blobFieldType);

        RecordType recordType = typeManager.newRecordType(new QName(NS, "file"));
        recordType.addFieldTypeEntry(blobFieldType.getId(), true);
        recordType = typeManager.createRecordType(recordType);


        // Upload a blob that, based upon the current default config, should end up in HBase
        //  (> 5000 bytes and < 200000 bytes)
        byte[] data = makeBlobData(10000);
        Blob blob = new Blob("application/octet-stream", (long) data.length, null);
        OutputStream blobStream = repository.getOutputStream(blob);
        IOUtils.copy(new ByteArrayInputStream(data), blobStream);
        blobStream.close();
        assertTrue(blob.getValue() != null);

        // Create a record with this blob
        Record record = repository.newRecord();
        record.setRecordType(new QName(NS, "file"));
        record.setField(new QName(NS, "data"), blob);
        record = repository.create(record);
    }
View Full Code Here

    @Test
    public void testScanners() throws Exception {
        LilyClient client = lilyProxy.getLilyServerProxy().getClient();

        // Obtain a repository
        Repository repository = client.getRepository();
        IdGenerator idGenerator = repository.getIdGenerator();

        String NS = "org.lilyproject.client.test";

        // Create a field type and record type
        TypeManager typeManager = repository.getTypeManager();
        FieldType fieldType = typeManager.newFieldType("STRING", new QName(NS, "scanfield"), Scope.VERSIONED);
        fieldType = typeManager.createFieldType(fieldType);

        RecordType recordType = typeManager.newRecordType(new QName(NS, "scanrt"));
        recordType.addFieldTypeEntry(fieldType.getId(), true);
        recordType = typeManager.createRecordType(recordType);

        // Create some records
        for (int i = 0; i < 10; i++) {
            Record record = repository.newRecord();
            record.setId(repository.getIdGenerator().newRecordId("A" + i));
            record.setRecordType(new QName(NS, "scanrt"));
            record.setField(new QName(NS, "scanfield"), "value " + i);
            repository.create(record);
        }

        // Do a scan
        RecordScan scan = new RecordScan();
        scan.setStartRecordId(idGenerator.newRecordId("A"));
        scan.setStopRecordId(idGenerator.newRecordId("B"));

        RecordScanner scanner = repository.getScanner(scan);
        int i = 0;
        while (scanner.next() != null) {
            i++;
        }
View Full Code Here

        log.info("The active repository decorators are: " + configuredDecorators);

        RepositoryDecoratorChain chain = new RepositoryDecoratorChain();

        Repository nextInChain = repository;
        chain.addEntryAtStart(RepositoryDecoratorChain.UNDECORATED_REPOSITORY_KEY, nextInChain);

        for (int i = configuredDecorators.size() - 1; i >=0; i--) {
            String decoratorName = configuredDecorators.get(i);
            RepositoryDecoratorFactory factory = decorators.get(decoratorName);
View Full Code Here

            HTableInterface nonAuthRecordTable = LilyHBaseSchema.getRecordTable(tableFactory, key.getRepositoryName(),
                    key.getTableName(), true);
            HTableInterface recordTable = wrapWithAuthorization(nonAuthRecordTable);

            Repository repo = new RemoteRepository(key, transceiver, avroConverter, this, blobManager,
                    recordTable, nonAuthRecordTable, tableManager, getRecordFactory());
            if ("true".equals(System.getProperty("lilyclient.trace"))) {
                repo = TracingRepository.wrap(repo);
            }
            return repo;
View Full Code Here

TOP

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

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.