Package org.lilyproject.client

Examples of org.lilyproject.client.LilyClient


        return confDir;
    }

    @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);
View Full Code Here


    @Override
    public RecordReader<RecordIdWritable, RecordWritable> createRecordReader(InputSplit inputSplit,
            TaskAttemptContext taskAttemptContext) throws IOException, InterruptedException {

        LilyClient lilyClient = null;
        try {
            lilyClient = new LilyClient(zkConnectString, 30000);
        } catch (Exception e) {
            throw new IOException("Error setting up LilyClient", e);
        }

        LRepository repository = null;
        try {
            repository = lilyClient.getRepository(repositoryName);
        } catch (RepositoryException e) {
            throw new IOException("Error getting Lily repository object", e);
        }

        // Build RecordScan
        RecordScan scan = getScan(repository);

        // Change the start/stop record IDs on the scan to the current split
        TableSplit split = (TableSplit)inputSplit;
        scan.setRawStartRecordId(split.getStartRow());
        scan.setRawStopRecordId(split.getEndRow());

        RecordScanner scanner = null;
        try {
            String hbaseTableName = Bytes.toString(split.getTableName());
            String repositoryTableName = RepoAndTableUtil.extractLilyTableName(repositoryName, hbaseTableName);
            scanner = lilyClient.getRepository(repositoryName).getTable(repositoryTableName).getScanner(scan);
        } catch (RepositoryException e) {
            Closer.close(lilyClient);
            throw new IOException("Error setting up RecordScanner", e);
        }
View Full Code Here

    @Override
    public RecordReader<RecordIdWritable, IdRecordWritable> createRecordReader(InputSplit inputSplit,
            TaskAttemptContext taskAttemptContext) throws IOException, InterruptedException {

        LilyClient lilyClient = null;
        try {
            lilyClient = new LilyClient(zkConnectString, 30000);
        } catch (Exception e) {
            throw new IOException("Error setting up LilyClient", e);
        }

        LRepository repository = null;
        try {
            repository = lilyClient.getRepository(repositoryName);
        } catch (RepositoryException e) {
            throw new IOException("Error getting Lily repository object", e);
        }

        // Build RecordScan
        RecordScan scan = getScan(repository);

        // Change the start/stop record IDs on the scan to the current split
        TableSplit split = (TableSplit)inputSplit;
        scan.setRawStartRecordId(split.getStartRow());
        scan.setRawStopRecordId(split.getEndRow());

        IdRecordScanner scanner = null;
        try {
            String hbaseTableName = Bytes.toString(split.getTableName());
            String repositoryTableName = RepoAndTableUtil.extractLilyTableName(repositoryName, hbaseTableName);
            scanner = lilyClient.getRepository(repositoryName).getTable(repositoryTableName).getScannerWithIds(scan);
        } catch (RepositoryException e) {
            Closer.close(lilyClient);
            throw new IOException("Error setting up RecordScanner", e);
        }
View Full Code Here

        return confDir;
    }

    @Test
    public void testOne() throws Exception {
        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);
View Full Code Here

     * Creates a LilyClient based on the information found in the Configuration object.
     */
    public static LilyClient getLilyClient(Configuration conf) throws InterruptedException {
        String zkConnectString = conf.get(ZK_CONNECT_STRING);
        try {
            return new LilyClient(zkConnectString, 30000);
        } catch (InterruptedException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
View Full Code Here

    @Test
    public void test() throws Exception {
        LilyProxy lilyProxy = createLilyProxy();

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

        RepositoryModelImpl repositoryModel = new RepositoryModelImpl(lilyProxy.getLilyServerProxy().getZooKeeper());
        repositoryModel.create("repo1");
        assertTrue(repositoryModel.waitUntilRepositoryInState("repo1", RepositoryLifecycleState.ACTIVE, 60000L));
        repositoryModel.create("repo2");
        assertTrue(repositoryModel.waitUntilRepositoryInState("repo2", RepositoryLifecycleState.ACTIVE, 60000L));
        repositoryModel.close();

        // Make a schema
        TypeManager typeMgr = client.getDefaultRepository().getTypeManager();

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

        QName field2 = new QName("ns", "f2");
        FieldType fieldType2 = typeMgr.newFieldType(typeMgr.getValueType("STRING"), field2, Scope.NON_VERSIONED);
        fieldType2 = typeMgr.createFieldType(fieldType2);

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

        DecoratingRepositoryManager repositoryMgr = (DecoratingRepositoryManager)lilyProxy.getLilyServerProxy()
                .getLilyServerTestingUtility().getRuntime().getModuleById("repository")
                .getApplicationContext().getBean("repositoryManager");
        IdentityHashMap<Object, Object> chains = new IdentityHashMap<Object, Object>();

        // Test the decorator is applied for each repository and each table
        for (String repositoryName : new String[] {"default", "repo1", "repo2"}) {
            LRepository repository = client.getRepository(repositoryName);

            repository.getTableManager().createTable("table1");
            repository.getTableManager().createTable("table2");

            for (String tableName : new String[] {"record", "table1", "table2"}) {
                LTable table = repository.getTable(tableName);
                Record record = table.newRecord();
                record.setRecordType(typeName);
                record.setField(field1, "foobar");
                record = table.create(record);
                assertEquals("foo", record.getField(field2));
                assertEquals("foo", table.read(record.getId()).getField(field2));

                // Test we can get access to our test decorator: this is something that is occasionally useful
                // in test cases to check certain conditions, e.g. if the decorator would have async side effects.
                RepositoryDecoratorChain chain = repositoryMgr.getRepositoryDecoratorChain(repositoryName, tableName);
                assertNotNull(chain);
                assertNotNull(chain.getDecorator(TestRepositoryDecoratorFactory.NAME));
                chains.put(chain.getDecorator(TestRepositoryDecoratorFactory.NAME), null);
                assertEquals(2, chain.getEntries().size());
            }
        }

        // There should be one instance of the decorator created for each repository-table combination (that
        // was accessed)
        assertEquals(3 * 3, chains.size());

        // Check that if we ask the same table twice, we get the same instance (verifies cache works)
        assertTrue(client.getRepository("repo1").getTable("table1") == client.getRepository("repo1").getTable("table1"));

        lilyProxy.stop();

        // Check each of the decorators was properly closed
        assertEquals(9, TestRepositoryDecoratorFactory.CLOSE_COUNT.get());
View Full Code Here

                nrOfTimes = Integer.valueOf(arg.substring(2));
            }
        }
        lilyProxy = new LilyProxy();
        lilyProxy.start();
        LilyClient lilyClient = lilyProxy.getLilyServerProxy().getClient();
        repository = lilyClient.getRepository();
        typeManager = repository.getTypeManager();
        resetDurations();
    }
View Full Code Here

     * The purpose of this test is to check that after resetLilyState, and when continuing to use
     * 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();
        }

        lilyClient.close();
    }
View Full Code Here

     * that it hence has to install new ZooKeeper watchers.
     */
    @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

     * that the blobs work remotely and it was able to retrieve the blob stores config from
     * ZooKeeper.
     */
    @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();
View Full Code Here

TOP

Related Classes of org.lilyproject.client.LilyClient

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.