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());
}
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();
}
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);
}
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());
}
}
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();
}
Aggregations