use of com.nearinfinity.honeycomb.mysql.schema.IndexSchema in project honeycomb by altamiracorp.
the class ITUtils method assertRowCount.
/**
* Check that the table open on the proxy has the expected number of data rows
* and index rows on each index (checks both ascending and descending
* directions). Note: this could be very slow for big tables.
* @param proxy HandlerProxy with table already open
* @param schema TableSchema of open table
* @param expectedRowCount Expected number of rows
*/
public static void assertRowCount(final HandlerProxy proxy, final TableSchema schema, final long expectedRowCount) {
checkState(proxy.getTableName() != null, "Proxy must have an open table.");
checkNotNull(schema);
verifyRowCount(expectedRowCount);
proxy.startTableScan();
assertResultCount(proxy, expectedRowCount);
proxy.endScan();
QueryKey queryKey;
for (IndexSchema indexSchema : schema.getIndices()) {
queryKey = new QueryKey(indexSchema.getIndexName(), QueryType.INDEX_FIRST, ImmutableMap.<String, ByteBuffer>of());
proxy.startIndexScan(queryKey.serialize());
assertResultCount(proxy, expectedRowCount);
proxy.endScan();
queryKey = new QueryKey(indexSchema.getIndexName(), QueryType.INDEX_LAST, ImmutableMap.<String, ByteBuffer>of());
proxy.startIndexScan(queryKey.serialize());
assertResultCount(proxy, expectedRowCount);
proxy.endScan();
}
}
use of com.nearinfinity.honeycomb.mysql.schema.IndexSchema in project honeycomb by altamiracorp.
the class MySqlBugIT method getTableSchema.
/**
* Provides the {@link com.nearinfinity.honeycomb.mysql.schema.TableSchema} to use for a test case
*
* @return The schema used for testing
*/
@Override
protected TableSchema getTableSchema() {
final List<ColumnSchema> columns = Lists.newArrayList();
final List<IndexSchema> indices = Lists.newArrayList();
// Add nullable, non-autoincrementing columns
columns.add(ColumnSchema.builder(TestConstants.COLUMN1, ColumnType.LONG).build());
columns.add(ColumnSchema.builder(TestConstants.COLUMN2, ColumnType.LONG).build());
// Add non-unique index on one column
indices.add(new IndexSchema(TestConstants.INDEX1, Lists.newArrayList(TestConstants.COLUMN1), false));
// Add non-unique compound index on (c1, c2)
indices.add(new IndexSchema(TestConstants.INDEX2, Lists.newArrayList(TestConstants.COLUMN1, TestConstants.COLUMN2), false));
// Add unique index on one column
indices.add(new IndexSchema(TestConstants.INDEX3, Lists.newArrayList(TestConstants.COLUMN1), true));
return new TableSchema(columns, indices);
}
use of com.nearinfinity.honeycomb.mysql.schema.IndexSchema in project honeycomb by altamiracorp.
the class Verify method isValidIndexSchema.
/**
* Verifies that the index schema only index columns for columns that are available
* @param indices A mapping of the index details, not null
* @param columns A mapping of column details, not null
* @throws NullPointerException Thrown if the indices or columns container is null
* @throws IllegalArgumentException Thrown if a {@link IndexSchema} indexes
* a column that is not an available column
*/
public static void isValidIndexSchema(final Collection<IndexSchema> indices, final Collection<ColumnSchema> columns) {
checkNotNull(indices);
checkNotNull(columns);
Set<String> columnNames = Sets.newHashSet();
for (ColumnSchema column : columns) {
columnNames.add(column.getColumnName());
}
for (final IndexSchema index : indices) {
for (final String column : index.getColumns()) {
if (!columnNames.contains(column)) {
throw new IllegalArgumentException("Only columns in the table may be indexed.");
}
}
}
}
use of com.nearinfinity.honeycomb.mysql.schema.IndexSchema in project honeycomb by altamiracorp.
the class HandlerProxyTest method testAddUniqueIndex.
@Test(expected = IllegalArgumentException.class)
public void testAddUniqueIndex() {
when(storeFactory.createStore(anyString())).thenReturn(storageMock);
when(storageMock.openTable(anyString())).thenReturn(tableMock);
proxy.openTable(TEST_TABLE_NAME);
verify(storeFactory, times(1)).createStore(eq(TEST_TABLE_NAME));
verify(storageMock, times(1)).openTable(eq(TEST_TABLE_NAME));
final IndexSchema uniqueIndex = new IndexSchema("uniqueIdx", ImmutableList.<String>of(TEST_COLUMN), true);
proxy.addIndex(TEST_INDEX, uniqueIndex.serialize());
verify(storageMock, never()).addIndex(eq(TEST_TABLE_NAME), eq(INDEX_SCHEMA));
verify(tableMock, never()).insertTableIndex(eq(INDEX_SCHEMA));
verify(tableMock, never()).flush();
}
use of com.nearinfinity.honeycomb.mysql.schema.IndexSchema in project honeycomb by altamiracorp.
the class VerifyTest method testIsValidTableSchemaValidSchema.
@Test
public void testIsValidTableSchemaValidSchema() {
final List<ColumnSchema> columns = ImmutableList.<ColumnSchema>of(ColumnSchema.builder(COLUMN_B, ColumnType.LONG).setIsAutoIncrement(true).build());
Verify.isValidTableSchema(new TableSchema(columns, ImmutableList.<IndexSchema>of()));
}
Aggregations