use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.
the class SchemaChangeLogServiceImplTest method recordChangeSets_withExecutionOrder.
@Test
public void recordChangeSets_withExecutionOrder() {
// Given
final int initialExecOrder = random.nextInt(10) + 1;
final int numChangeSets = random.nextInt(100) + 1;
final List<ChangeSet> changeSets = new ArrayList<>(numChangeSets);
for (int i = 0; i < numChangeSets; i++) {
changeSets.add(newChangeSet("id" + (i + 1)));
}
doNothing().when(schemaChangeLogDao).insertChangeLog(anyString(), any(SchemaChangeLog.class));
// When
List<SchemaChangeLog> schemaChangeLogs = schemaChangeLogService.recordChangeSets("namespace", initialExecOrder, changeSets);
// Then
MatcherAssert.assertThat(schemaChangeLogs.size(), equalTo(numChangeSets));
for (int i = 0; i < numChangeSets; i++) {
SchemaChangeLog schemaChangeLog = schemaChangeLogs.get(i);
ChangeSet changeSet = changeSets.get(i);
MatcherAssert.assertThat(schemaChangeLog.getId(), equalTo(changeSet.getId()));
int expectedExecOrder = initialExecOrder + i;
MatcherAssert.assertThat(schemaChangeLog.getExecOrder(), equalTo(expectedExecOrder));
}
}
use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.
the class HbaseSchemaServiceImpl method getSchemaStatus.
/**
* This implementation uses the executed schema change logs to compare against the specified {@code changeSets} to
* check the current schema status, regardless of how the actual schema looks like.
*/
// TODO May be a good idea to compare the actual tables against each of the change sets in the future.
@Override
public HbaseSchemaStatus getSchemaStatus(String namespace, List<ChangeSet> changeSets) {
if (CollectionUtils.isEmpty(changeSets)) {
throw new IllegalArgumentException("changeSets must not be empty");
}
if (!schemaChangeLogService.isAvailable(namespace)) {
return HbaseSchemaStatus.NONE;
}
List<SchemaChangeLog> schemaChangeLogs = schemaChangeLogService.getSchemaChangeLogs(namespace);
if (CollectionUtils.isEmpty(schemaChangeLogs)) {
return HbaseSchemaStatus.NONE;
}
List<ChangeSet> unexecutedChangeSets;
ChangeSetManager changeSetManager = new ChangeSetManager(changeSets);
try {
unexecutedChangeSets = changeSetManager.filterExecutedChangeSets(schemaChangeLogs);
} catch (IllegalArgumentException e) {
logger.error("[{}] Invalid hbase schema, cause : {}", namespace, e.getMessage());
return HbaseSchemaStatus.INVALID;
}
if (CollectionUtils.isEmpty(unexecutedChangeSets)) {
return HbaseSchemaStatus.VALID;
}
return HbaseSchemaStatus.VALID_OUT_OF_DATE;
}
use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.
the class SchemaChangeLogServiceImpl method recordChangeSets.
@Override
public List<SchemaChangeLog> recordChangeSets(String namespace, int executionOrder, List<ChangeSet> changeSets) {
if (CollectionUtils.isEmpty(changeSets)) {
return Collections.emptyList();
}
int startingOrder = executionOrder;
long executionTimestamp = System.currentTimeMillis();
List<SchemaChangeLog> schemaChangeLogs = new ArrayList<>();
for (ChangeSet changeSet : changeSets) {
SchemaChangeLog schemaChangeLog = recordChangeSet(namespace, executionTimestamp, startingOrder, changeSet);
schemaChangeLogs.add(schemaChangeLog);
startingOrder++;
}
return schemaChangeLogs;
}
use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.
the class HbaseSchemaServiceImplTest method getSchemaStatus_validSchemaChangeLogs.
@Test
public void getSchemaStatus_validSchemaChangeLogs() {
final String namespace = "namespace";
final List<ChangeSet> changeSets = Arrays.asList(newChangeSet("id1", "value1"), newChangeSet("id2", "value2"), newChangeSet("id3", "value3"));
final List<SchemaChangeLog> schemaChangeLogs = Arrays.asList(newSchemaChangeLog("id1", "value1", 1), newSchemaChangeLog("id2", "value2", 2), newSchemaChangeLog("id3", "value3", 3));
when(schemaChangeLogService.isAvailable(namespace)).thenReturn(true);
when(schemaChangeLogService.getSchemaChangeLogs(namespace)).thenReturn(schemaChangeLogs);
HbaseSchemaStatus schemaStatus = hbaseSchemaService.getSchemaStatus(namespace, changeSets);
MatcherAssert.assertThat(schemaStatus, is(HbaseSchemaStatus.VALID));
}
use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.
the class HbaseSchemaServiceImplTest method getSchemaStatus_invalidSchemaChangeLogs.
@Test
public void getSchemaStatus_invalidSchemaChangeLogs() {
final String namespace = "namespace";
final List<ChangeSet> changeSets = Arrays.asList(newChangeSet("id1", "value1"), newChangeSet("id2", "value2"), newChangeSet("id3", "value3"));
final List<SchemaChangeLog> schemaChangeLogs = Arrays.asList(newSchemaChangeLog("id1", "value2", 2), newSchemaChangeLog("id2", "value1", 1), newSchemaChangeLog("someOtherId", "value3", 3));
when(schemaChangeLogService.isAvailable(namespace)).thenReturn(true);
when(schemaChangeLogService.getSchemaChangeLogs(namespace)).thenReturn(schemaChangeLogs);
HbaseSchemaStatus schemaStatus = hbaseSchemaService.getSchemaStatus(namespace, changeSets);
MatcherAssert.assertThat(schemaStatus, is(HbaseSchemaStatus.INVALID));
}
Aggregations