Search in sources :

Example 36 with ChangeSet

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));
}
Also used : TableName(org.apache.hadoop.hbase.TableName) HbaseAdminOperation(com.navercorp.pinpoint.common.hbase.HbaseAdminOperation) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 37 with ChangeSet

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));
}
Also used : HbaseAdminOperation(com.navercorp.pinpoint.common.hbase.HbaseAdminOperation) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 38 with ChangeSet

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));
}
Also used : CreateColumnFamilyChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateColumnFamilyChange) ModifyTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.ModifyTableChange) CreateTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) CreateTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange) TableChange(com.navercorp.pinpoint.hbase.schema.reader.core.TableChange) ModifyTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.ModifyTableChange) ColumnFamilyConfiguration(com.navercorp.pinpoint.hbase.schema.reader.core.ColumnFamilyConfiguration) Test(org.junit.Test)

Example 39 with ChangeSet

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));
}
Also used : ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog) Test(org.junit.Test)

Aggregations

ChangeSet (com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet)39 Test (org.junit.Test)28 SchemaChangeLog (com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog)23 ArrayList (java.util.ArrayList)8 TableChange (com.navercorp.pinpoint.hbase.schema.reader.core.TableChange)7 CreateTableChange (com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange)6 ModifyTableChange (com.navercorp.pinpoint.hbase.schema.reader.core.ModifyTableChange)6 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)6 HbaseSchemaStatus (com.navercorp.pinpoint.hbase.schema.core.HbaseSchemaStatus)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 CreateColumnFamilyChange (com.navercorp.pinpoint.hbase.schema.reader.core.CreateColumnFamilyChange)4 ColumnFamilyChange (com.navercorp.pinpoint.hbase.schema.reader.core.ColumnFamilyChange)3 HbaseAdminOperation (com.navercorp.pinpoint.common.hbase.HbaseAdminOperation)2 ChangeSetManager (com.navercorp.pinpoint.hbase.schema.core.ChangeSetManager)2 HbaseSchemaCommandManager (com.navercorp.pinpoint.hbase.schema.core.command.HbaseSchemaCommandManager)2 InvalidHbaseSchemaException (com.navercorp.pinpoint.hbase.schema.reader.InvalidHbaseSchemaException)2 ColumnFamilyConfiguration (com.navercorp.pinpoint.hbase.schema.reader.core.ColumnFamilyConfiguration)2 TableCommand (com.navercorp.pinpoint.hbase.schema.core.command.TableCommand)1 HbaseSchemaParseException (com.navercorp.pinpoint.hbase.schema.reader.HbaseSchemaParseException)1 TableConfiguration (com.navercorp.pinpoint.hbase.schema.reader.core.TableConfiguration)1