Package com.nearinfinity.honeycomb.mysql.schema

Examples of com.nearinfinity.honeycomb.mysql.schema.TableSchema


    @Test(expected = TableNotFoundException.class)
    public void testRenameExistingTableNoAutoFlush() throws Exception {
        String originalName = "OriginalName";
        String newName = "NewName";

        TableSchema origSchema = TABLE_SCHEMA_GEN.next();

        // Configure the table to disable auto flush
        HTableInterface hTableSpy = PowerMockito.spy(MockHTable.create());
        Mockito.when(hTableSpy.isAutoFlush()).thenReturn(false);

        hbaseMetadata.createTable(originalName, origSchema);

        long origId = hbaseMetadata.getTableId(originalName);
        hbaseMetadata.renameExistingTable(originalName, newName);

        long newId = hbaseMetadata.getTableId(newName);

        assertEquals(origId, newId);
        Collection<ColumnSchema> origSchemaColumns = origSchema.getColumns();
        TableSchema newSchema = hbaseMetadata.getSchema(newId);
        for (ColumnSchema columnSchema : newSchema.getColumns()) {
            assertTrue(origSchemaColumns.contains(columnSchema));
        }

        // Trying to access the id of the old table name will result in an exception
        hbaseMetadata.getTableId(originalName);
View Full Code Here


        hbaseMetadata.createTableIndex(1, null);
    }

    @Test
    public void testCreateIndex() {
        final TableSchema tableSchema = new TableSchema(COLUMN_SCHEMAS, ImmutableList.<IndexSchema>of());

        // Create a new table with the configured details
        hbaseMetadata.createTable(TABLE_NAME, tableSchema);
        final long tableId = hbaseMetadata.getTableId(TABLE_NAME);

        // Verify that the table schema has no indices after creation
        final TableSchema schemaBefore = hbaseMetadata.getSchema(tableId);
        assertNotNull(schemaBefore);
        assertTrue(schemaBefore.getIndices().isEmpty());

        // Add a new index to the table
        hbaseMetadata.createTableIndex(tableId,
                new IndexSchema(INDEX_NAME, ImmutableList.<String>of(COLUMN_NAME), false));

        // Verify that the table schema has been correctly updated

        final TableSchema schemaAfter = hbaseMetadata.getSchema(tableId);
        assertNotNull(schemaAfter);

        final Collection<IndexSchema> schemaIndices = schemaAfter.getIndices();
        assertEquals(1, schemaIndices.size());


        final IndexSchema newIndexDetails = Iterables.find(schemaIndices, indexPredicate);
        assertNotNull(newIndexDetails);
View Full Code Here

        hbaseMetadata.deleteTableIndex(1, "");
    }

    @Test
    public void testDeleteIndex() {
        final TableSchema tableSchema =
                new TableSchema(COLUMN_SCHEMAS,
                        ImmutableList.<IndexSchema>of(
                                new IndexSchema(INDEX_NAME, Lists.newArrayList(COLUMN_NAME), false)));

        // Create a new table with the configured details
        hbaseMetadata.createTable(TABLE_NAME, tableSchema);
        final long tableId = hbaseMetadata.getTableId(TABLE_NAME);


        // Verify that the table schema contains indices after creation

        final TableSchema schemaBefore = hbaseMetadata.getSchema(tableId);
        assertNotNull(schemaBefore);

        final Collection<IndexSchema> schemaIndices = schemaBefore.getIndices();
        assertEquals(1, schemaIndices.size());

        final IndexSchema newIndexDetails = Iterables.find(schemaIndices, indexPredicate);
        assertNotNull(newIndexDetails);

        final List<String> indexColumns = newIndexDetails.getColumns();
        assertEquals(1, indexColumns.size());
        assertEquals(COLUMN_NAME, indexColumns.get(0));

        // Verify that the index exists after table creation
        final Map<String, Long> tableIndexInfo = hbaseMetadata.getIndexIds(tableId);
        assertEquals(1, tableIndexInfo.size());
        assertTrue(tableIndexInfo.containsKey(INDEX_NAME));

        // Remove an existing index from the table
        hbaseMetadata.deleteTableIndex(tableId, INDEX_NAME);

        // Verify that the table schema has been correctly updated
        final TableSchema schemaAfter = hbaseMetadata.getSchema(tableId);
        assertNotNull(schemaAfter);
        assertTrue(schemaAfter.getIndices().isEmpty());

        // Verify that the index has been removed correctly
        assertTrue(hbaseMetadata.getIndexIds(tableId).isEmpty());
    }
View Full Code Here

        assertTrue(hbaseMetadata.getIndexIds(tableId).isEmpty());
    }

    @Test
    public void testAutoInc() throws Exception {
        TableSchema table = TABLE_SCHEMA_GEN.next();
        final String tableName = TableSchemaGenerator.MYSQL_NAME_GEN.next();

        hbaseMetadata.createTable(tableName, table);

        long tableId = hbaseMetadata.getTableId(tableName);
View Full Code Here

        assertEquals(hbaseMetadata.getAutoInc(tableId), 13);
    }

    @Test
    public void testRowCount() throws Exception {
        TableSchema table = TABLE_SCHEMA_GEN.next();
        final String tableName = TableSchemaGenerator.MYSQL_NAME_GEN.next();

        hbaseMetadata.createTable(tableName, table);

        long tableId = hbaseMetadata.getTableId(tableName);
View Full Code Here

    public void testBuildWithoutSortOrderFails(){
        builder.build();
    }

    private TableSchema getSchema() {
        return new TableSchema(
                ImmutableList.<ColumnSchema>of(
                        ColumnSchema.builder("c1", ColumnType.BINARY)
                                .setMaxLength(16)
                                .build()),
                ImmutableList.<IndexSchema>of());
View Full Code Here

    public void testIndexRowKeyStrings() {
        String columnName = "c1";
        String indexName = "i1";
        ColumnSchema columnSchema = ColumnSchema.builder("default", ColumnType.DATETIME).build();
        IndexSchema indexSchema = new IndexSchema(indexName, ImmutableList.of(columnName), false);
        TableSchema tableSchema = new TableSchema(ImmutableList.of(columnSchema), ImmutableList.of(indexSchema));

        Generator<RowKey> rowkeysGen = RowKeyGenerator.getAscIndexRowKeyGenerator(tableSchema);
        List<RowKey> rowkeys = Lists.newArrayList(Iterables.toIterable(rowkeysGen));
        Collections.sort(rowkeys);
View Full Code Here

        HBaseStore store = new HBaseStore(metadata, tableFactory, cache);
        factory = new MutationFactory(store);
        factory.setColumnFamily("nic");

        TableSchema schema = new TableSchema(COLUMNS, INDICES);

        store.createTable(TABLE, schema);
        tableId = store.getTableId(TABLE);
    }
View Full Code Here

        hbaseMetadata = new HBaseMetadata(provider);
        hbaseMetadata.setColumnFamily("nic");

        for (int i = 0; i < 20; i++) {
            TableSchema schema = tableSchemaGen.next();
            final String tableName = TableSchemaGenerator.MYSQL_NAME_GEN.next();
            tableSchemas.put(tableName, schema);
            hbaseMetadata.createTable(tableName, schema);
        }
    }
View Full Code Here

    @Test
    public void testSchemaGet() throws Exception {
        long tableId;
        for (String tableName : tableSchemas.keySet()) {
            TableSchema expected = tableSchemas.get(tableName);

            tableId = hbaseMetadata.getTableId(tableName);

            TableSchema actual = hbaseMetadata.getSchema(tableId);
            Assert.assertEquals(expected, actual);
        }
    }
View Full Code Here

TOP

Related Classes of com.nearinfinity.honeycomb.mysql.schema.TableSchema

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.