use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.
the class HbaseSchemaCommandManagerTest method modifyingTheSameTableMultipleTimesShouldBeMerged.
@Test
public void modifyingTheSameTableMultipleTimesShouldBeMerged() {
String namespace = "namespace";
String tableName = "table";
String existingColumnFamily = "CF";
String newColumnFamily1 = "CF1";
String newColumnFamily2 = "CF2";
HTableDescriptor existingHtd = createHtd(namespace, tableName, existingColumnFamily);
HbaseSchemaCommandManager manager = new HbaseSchemaCommandManager(namespace, null, Arrays.asList(new HTableDescriptor(existingHtd)));
ChangeSet createColumnFamilyChangeSet1 = newChangeSet(newTableChange(ChangeType.MODIFY, tableName, newColumnFamilyChange(newColumnFamily1)));
ChangeSet createColumnFamilyChangeSet2 = newChangeSet(newTableChange(ChangeType.MODIFY, tableName, newColumnFamilyChange(newColumnFamily2)));
manager.applyChangeSet(createColumnFamilyChangeSet1);
manager.applyChangeSet(createColumnFamilyChangeSet2);
// verify schema snapshot
List<HTableDescriptor> schemaSnapshot = manager.getSchemaSnapshot();
assertThat(schemaSnapshot.size(), is(1));
HTableDescriptor snapshotTable = schemaSnapshot.get(0);
assertThat(snapshotTable.getTableName(), is(TableName.valueOf(namespace, tableName)));
List<String> snapshotColumnFamilies = snapshotTable.getFamilies().stream().map(HColumnDescriptor::getNameAsString).collect(Collectors.toList());
assertThat(snapshotColumnFamilies, contains(existingColumnFamily, newColumnFamily1, newColumnFamily2));
// verify command - should add 2 column families
HbaseAdminOperation mockHbaseAdminOperation = Mockito.mock(HbaseAdminOperation.class);
when(mockHbaseAdminOperation.getTableDescriptor(existingHtd.getTableName())).thenReturn(existingHtd);
doNothing().when(mockHbaseAdminOperation).addColumn(any(TableName.class), any(HColumnDescriptor.class));
doNothing().when(mockHbaseAdminOperation).createTable(any(HTableDescriptor.class));
for (TableCommand tableCommand : manager.getCommands()) {
tableCommand.execute(mockHbaseAdminOperation);
}
verify(mockHbaseAdminOperation, times(2)).addColumn(any(TableName.class), any(HColumnDescriptor.class));
verify(mockHbaseAdminOperation, never()).createTable(any(HTableDescriptor.class));
}
use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.
the class HbaseSchemaCommandManagerTest method creatingAndModifyingTheSameTableShouldBeMerged.
@Test
public void creatingAndModifyingTheSameTableShouldBeMerged() {
String namespace = "namespace";
String tableName = "table";
String columnFamily1 = "CF1";
String columnFamily2 = "CF2";
String columnFamily3 = "CF3";
HbaseSchemaCommandManager manager = new HbaseSchemaCommandManager(namespace, null);
ChangeSet createTableChangeSet = newChangeSet(newTableChange(ChangeType.CREATE, tableName, newColumnFamilyChange(columnFamily1)));
ChangeSet addColumnFamilyChangeSet1 = newChangeSet(newTableChange(ChangeType.MODIFY, tableName, newColumnFamilyChange(columnFamily2)));
ChangeSet addColumnFamilyChangeSet2 = newChangeSet(newTableChange(ChangeType.MODIFY, tableName, newColumnFamilyChange(columnFamily3)));
manager.applyChangeSet(createTableChangeSet);
manager.applyChangeSet(addColumnFamilyChangeSet1);
manager.applyChangeSet(addColumnFamilyChangeSet2);
// verify schema snapshot
List<HTableDescriptor> schemaSnapshot = manager.getSchemaSnapshot();
assertThat(schemaSnapshot.size(), is(1));
HTableDescriptor snapshotTable = schemaSnapshot.get(0);
assertThat(snapshotTable.getTableName(), is(TableName.valueOf(namespace, tableName)));
List<String> snapshotColumnFamilies = snapshotTable.getFamilies().stream().map(HColumnDescriptor::getNameAsString).collect(Collectors.toList());
assertThat(snapshotColumnFamilies, contains(columnFamily1, columnFamily2, columnFamily3));
// verify command - should create 1 table (with all 3 column families)
HbaseAdminOperation mockHbaseAdminOperation = Mockito.mock(HbaseAdminOperation.class);
when(mockHbaseAdminOperation.tableExists(TableName.valueOf(namespace, tableName))).thenReturn(false);
doNothing().when(mockHbaseAdminOperation).createTable(any(HTableDescriptor.class));
for (TableCommand tableCommand : manager.getCommands()) {
tableCommand.execute(mockHbaseAdminOperation);
}
verify(mockHbaseAdminOperation, times(1)).createTable(any(HTableDescriptor.class));
}
use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.
the class XmlHbaseSchemaReaderTest method loadChangeSets.
@Test
public void loadChangeSets() {
final String schemaFilePath = "classpath:hbase-schema/test-hbase-schema.xml";
String expectedIncludeChangeSetId = "include-1";
List<TableChange> expectedIncludeChangeSetTableChanges = Arrays.asList(new CreateTableChange("IncludeTable1", TableConfiguration.EMPTY_CONFIGURATION, Arrays.asList(new CreateColumnFamilyChange("CF1", new ColumnFamilyConfiguration.Builder().timeToLive(5184000).build())), new CreateTableChange.SplitOption.Manual(Arrays.asList("\\x01", "\\x02", "\\x03"))));
String expectedChangeSetId1 = "id-1";
List<TableChange> expectedChangeSet1TableChanges = Arrays.asList(new CreateTableChange("Table1", new TableConfiguration.Builder().durability(TableConfiguration.Durability.ASYNC_WAL).build(), Arrays.asList(new CreateColumnFamilyChange("CF1", new ColumnFamilyConfiguration.Builder().timeToLive(86400).dataBlockEncoding(ColumnFamilyConfiguration.DataBlockEncoding.NONE).build()), new CreateColumnFamilyChange("CF2", ColumnFamilyConfiguration.EMPTY_CONFIGURATION)), new CreateTableChange.SplitOption.Auto(16)));
String expectedChangeSetId2 = "id-2";
List<TableChange> expectedChangeSet2TableChanges = Arrays.asList(new ModifyTableChange("Table1", TableConfiguration.EMPTY_CONFIGURATION, Arrays.asList(new CreateColumnFamilyChange("CF3", ColumnFamilyConfiguration.EMPTY_CONFIGURATION))));
List<ChangeSet> changeSets = reader.loadChangeSets(schemaFilePath);
assertThat(changeSets.size(), is(3));
ChangeSet includeChangeSet = changeSets.get(0);
assertThat(includeChangeSet, matches(expectedIncludeChangeSetId, expectedIncludeChangeSetTableChanges));
ChangeSet changeSet1 = changeSets.get(1);
assertThat(changeSet1, matches(expectedChangeSetId1, expectedChangeSet1TableChanges));
ChangeSet changeSet2 = changeSets.get(2);
assertThat(changeSet2, matches(expectedChangeSetId2, expectedChangeSet2TableChanges));
}
use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.
the class SchemaChangeLogServiceImplTest method recordChangeSet_withExecutionOrder.
@Test
public void recordChangeSet_withExecutionOrder() {
// Given
final ChangeSet changeSet = newChangeSet("id1");
final int executionOrder = random.nextInt(100) + 1;
doNothing().when(schemaChangeLogDao).insertChangeLog(anyString(), any(SchemaChangeLog.class));
// When
SchemaChangeLog schemaChangeLog = schemaChangeLogService.recordChangeSet("namespace", executionOrder, changeSet);
// Then
MatcherAssert.assertThat(schemaChangeLog.getId(), equalTo(changeSet.getId()));
MatcherAssert.assertThat(schemaChangeLog.getExecOrder(), equalTo(executionOrder));
}
Aggregations