Search in sources :

Example 26 with TableSchema

use of com.nearinfinity.honeycomb.mysql.schema.TableSchema in project honeycomb by altamiracorp.

the class HBaseMetadataTest method testDeleteIndex.

@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());
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema) Test(org.junit.Test)

Example 27 with TableSchema

use of com.nearinfinity.honeycomb.mysql.schema.TableSchema in project honeycomb by altamiracorp.

the class HBaseMetadataTest method testRenameExistingTableNoAutoFlush.

@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);
    hTableSpy.close();
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface) Test(org.junit.Test)

Example 28 with TableSchema

use of com.nearinfinity.honeycomb.mysql.schema.TableSchema in project honeycomb by altamiracorp.

the class MutationFactoryTest method testSetup.

@Before
public void testSetup() {
    HBaseTableFactory tableFactory = mock(HBaseTableFactory.class);
    HTableProvider provider = mock(HTableProvider.class);
    MockitoAnnotations.initMocks(this);
    MockHTable table = MockHTable.create();
    when(provider.get()).thenReturn(table);
    HBaseMetadata metadata = new HBaseMetadata(provider);
    metadata.setColumnFamily("nic");
    MetadataCache cache = new MetadataCache(metadata);
    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);
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) MockHTable(com.nearinfinity.honeycomb.MockHTable) Before(org.junit.Before)

Example 29 with TableSchema

use of com.nearinfinity.honeycomb.mysql.schema.TableSchema in project honeycomb by altamiracorp.

the class RowKeyTest method testIndexRowKeyStrings.

@Test
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);
    List<byte[]> encodedRowkeys = Lists.newArrayList();
    for (RowKey rowkey : rowkeys) {
        encodedRowkeys.add(rowkey.encode());
    }
    Collections.sort(encodedRowkeys, new Bytes.ByteArrayComparator());
    for (int i = 0; i < rowkeys.size(); i++) {
        RowKey rowKey = rowkeys.get(i);
        byte[] encodedRowKey = encodedRowkeys.get(i);
        Assert.assertArrayEquals(encodedRowKey, rowKey.encode());
    }
}
Also used : UnsignedBytes(com.google.common.primitives.UnsignedBytes) Bytes(org.apache.hadoop.hbase.util.Bytes) TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) RowKey(com.nearinfinity.honeycomb.hbase.rowkey.RowKey) ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema) Test(org.junit.Test)

Example 30 with TableSchema

use of com.nearinfinity.honeycomb.mysql.schema.TableSchema in project honeycomb by altamiracorp.

the class HBaseMetadataTest method testSchemaDeleteRemovesAllRowIds.

@Test
public void testSchemaDeleteRemovesAllRowIds() throws Exception {
    TableSchema schema = TABLE_SCHEMA_GEN.next();
    final String tableName = TableSchemaGenerator.MYSQL_NAME_GEN.next();
    hbaseMetadata.createTable(tableName, schema);
    long tableId = hbaseMetadata.getTableId(tableName);
    TableSchema expected = hbaseMetadata.getSchema(tableId);
    assertEquals(schema, expected);
    hbaseMetadata.deleteTable(tableName);
    ResultScanner results = table.getScanner(new Scan());
    // Table id counter
    assertTrue(results.next().getNoVersionMap().size() == 1);
    assertNull(results.next());
    results.close();
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) Scan(org.apache.hadoop.hbase.client.Scan) Test(org.junit.Test)

Aggregations

TableSchema (com.nearinfinity.honeycomb.mysql.schema.TableSchema)34 Test (org.junit.Test)17 IndexSchema (com.nearinfinity.honeycomb.mysql.schema.IndexSchema)12 ColumnSchema (com.nearinfinity.honeycomb.mysql.schema.ColumnSchema)9 IndexRowKey (com.nearinfinity.honeycomb.hbase.rowkey.IndexRowKey)5 AvroTableSchema (com.nearinfinity.honeycomb.mysql.gen.AvroTableSchema)5 Predicate (com.google.common.base.Predicate)1 ImmutableList (com.google.common.collect.ImmutableList)1 UnsignedBytes (com.google.common.primitives.UnsignedBytes)1 MockHTable (com.nearinfinity.honeycomb.MockHTable)1 Scanner (com.nearinfinity.honeycomb.Scanner)1 Table (com.nearinfinity.honeycomb.Table)1 IndexRowKeyBuilder (com.nearinfinity.honeycomb.hbase.rowkey.IndexRowKeyBuilder)1 RowKey (com.nearinfinity.honeycomb.hbase.rowkey.RowKey)1 HandlerProxy (com.nearinfinity.honeycomb.mysql.HandlerProxy)1 Row (com.nearinfinity.honeycomb.mysql.Row)1 HoneycombIntegrationTest (integrationtests.HoneycombIntegrationTest)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1