@Test public void testCreateDeleteTableWithSecondaryIndex() throws IOException { HTableDescriptor tableDesc = new HTableDescriptor( IndexMasterObserver.THEMIS_SECONDARY_INDEX_TABLE_NAME_PREFIX + "_a"); try { admin.createTable(tableDesc); Assert.fail(); } catch (IOException e) { Assert.assertTrue(e.getMessage().indexOf("is preserved") >= 0); } byte[] testMainTable = Bytes.toBytes("temp_test"); byte[] testIndexTable = Bytes.toBytes("__themis_index_temp_test_ThemisCF_Qualifier_test_index"); deleteTable(admin, testMainTable); tableDesc = new HTableDescriptor(testMainTable); tableDesc.addFamily(IndexMasterObserver.getSecondaryIndexFamily()); admin.createTable(tableDesc); HTableDescriptor[] tableDescs = admin.listTables(); for (HTableDescriptor desc : tableDescs) { Assert.assertFalse(Bytes.equals(testIndexTable, desc.getName())); } admin.disableTable(testMainTable); admin.deleteTable(testMainTable); tableDesc = new HTableDescriptor(testMainTable); HColumnDescriptor columnDesc = new HColumnDescriptor(INDEX_FAMILY); columnDesc.setValue(IndexMasterObserver.THEMIS_SECONDARY_INDEX_FAMILY_ATTRIBUTE_KEY, Boolean.TRUE.toString()); tableDesc.addFamily(columnDesc); try { admin.createTable(tableDesc); } catch (IOException e) { Assert.assertTrue(e.getMessage().indexOf("must be set on themis-enabled family") >= 0); } createTableForIndexTest(testMainTable); HTableDescriptor desc = admin.getTableDescriptor(testMainTable); Assert.assertNotNull(desc); Assert.assertNotNull(desc.getFamily(ColumnUtil.LOCK_FAMILY_NAME)); desc = admin.getTableDescriptor(testIndexTable); Assert.assertNotNull(desc); Assert.assertNotNull(desc.getFamily(Bytes .toBytes(IndexMasterObserver.THEMIS_SECONDARY_INDEX_TABLE_FAMILY))); Assert.assertNotNull(desc.getFamily(ColumnUtil.LOCK_FAMILY_NAME)); deleteTableForIndexTest(testMainTable); tableDescs = admin.listTables(); for (HTableDescriptor tempDesc : tableDescs) { if (Bytes.equals(tempDesc.getName(), testMainTable)) { Assert.fail("fail to delete table:" + Bytes.toString(testMainTable)); } else if (Bytes.equals(tempDesc.getName(), testIndexTable)) { Assert.fail("fail to delete table:" + Bytes.toString(testIndexTable)); } } }
protected static HColumnDescriptor getSecondaryIndexFamily() throws IOException { HColumnDescriptor desc = new HColumnDescriptor(THEMIS_SECONDARY_INDEX_TABLE_FAMILY); desc.setValue(ThemisMasterObserver.THEMIS_ENABLE_KEY, Boolean.TRUE.toString()); return desc; }
IndexMasterObserver extends BaseMasterObserver { protected static HColumnDescriptor getSecondaryIndexFamily() throws IOException { HColumnDescriptor desc = new HColumnDescriptor(THEMIS_SECONDARY_INDEX_TABLE_FAMILY); desc.setValue(ThemisMasterObserver.THEMIS_ENABLE_KEY, Boolean.TRUE.toString()); return desc; } }
IndexMasterObserver extends BaseMasterObserver { protected static HColumnDescriptor getSecondaryIndexFamily() throws IOException { HColumnDescriptor desc = new HColumnDescriptor(THEMIS_SECONDARY_INDEX_TABLE_FAMILY); desc.setValue(ThemisMasterObserver.THEMIS_ENABLE_KEY, Boolean.TRUE.toString()); return desc; }  }
IndexMasterObserver extends BaseMasterObserver { protected static HColumnDescriptor getSecondaryIndexFamily() throws IOException { HColumnDescriptor desc = new HColumnDescriptor(THEMIS_SECONDARY_INDEX_TABLE_FAMILY); desc.setValue(ThemisMasterObserver.THEMIS_ENABLE_KEY, Boolean.TRUE.toString()); return desc; }  @Override void preCreateTable(ObserverContext<MasterCoprocessorEnvironment> ctx,
      HTableDescriptor desc, HRegionInfo[] regions); @Override void preDeleteTable(ObserverContext<MasterCoprocessorEnvironment> ctx,
      byte[] tableName); @Override void postDeleteTable(ObserverContext<MasterCoprocessorEnvironment> ctx,
      byte[] tableName); }
IndexMasterObserver extends BaseMasterObserver { protected static HColumnDescriptor getSecondaryIndexFamily() throws IOException { HColumnDescriptor desc = new HColumnDescriptor(THEMIS_SECONDARY_INDEX_TABLE_FAMILY); desc.setValue(ThemisMasterObserver.THEMIS_ENABLE_KEY, Boolean.TRUE.toString()); return desc; }  @Override void preCreateTable(ObserverContext<MasterCoprocessorEnvironment> ctx,
      HTableDescriptor desc, HRegionInfo[] regions); @Override void preDeleteTable(ObserverContext<MasterCoprocessorEnvironment> ctx,
      byte[] tableName); @Override void postDeleteTable(ObserverContext<MasterCoprocessorEnvironment> ctx,
      byte[] tableName); static final String THEMIS_SECONDARY_INDEX_FAMILY_ATTRIBUTE_KEY; static final String THEMIS_SECONDARY_INDEX_NAME_SPLITOR; static final String THEMIS_SECONDARY_INDEX_TABLE_NAME_PREFIX; static final String THEMIS_SECONDARY_INDEX_TABLE_ATTRIBUTE_KEY; static final String THEMIS_SECONDARY_INDEX_TABLE_FAMILY; static final byte[] THEMIS_SECONDARY_INDEX_TABLE_FAMILY_BYTES; }