Search in sources :

Example 11 with SchemaChangeLog

use of com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog in project pinpoint by naver.

the class SchemaChangeLogServiceImplTest method getSchemaChangeLogs.

@Test
public void getSchemaChangeLogs() {
    // Given
    final int numSchemaChangeLogs = random.nextInt(100) + 1;
    final List<SchemaChangeLog> schemaChangeLogs = new ArrayList<>(numSchemaChangeLogs);
    for (int i = 0; i < numSchemaChangeLogs; i++) {
        int order = i + 1;
        schemaChangeLogs.add(newSchemaChangeLog("id" + order, order));
    }
    when(schemaChangeLogDao.getChangeLogs(anyString())).thenReturn(schemaChangeLogs);
    // When
    List<SchemaChangeLog> actualSchemaChangeLogs = schemaChangeLogService.getSchemaChangeLogs("namespace");
    // Then
    for (int i = 0; i < actualSchemaChangeLogs.size(); i++) {
        final SchemaChangeLog actualSchemaChangeLog = actualSchemaChangeLogs.get(i);
        final int expectedOrder = i + 1;
        final String expectedId = "id" + expectedOrder;
        MatcherAssert.assertThat(actualSchemaChangeLog.getId(), equalTo(expectedId));
        MatcherAssert.assertThat(actualSchemaChangeLog.getExecOrder(), equalTo(expectedOrder));
    }
}
Also used : ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog) Test(org.junit.Test)

Example 12 with SchemaChangeLog

use of com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog in project pinpoint by naver.

the class SchemaChangeLogServiceImplTest method recordChangeSets.

@Test
public void recordChangeSets() {
    // Given
    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", changeSets);
    // Then
    MatcherAssert.assertThat(schemaChangeLogs.size(), equalTo(numChangeSets));
    final int initialExecOrder = 1;
    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));
    }
}
Also used : ArrayList(java.util.ArrayList) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog) Test(org.junit.Test)

Example 13 with SchemaChangeLog

use of com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog in project pinpoint by naver.

the class SchemaChangeLogServiceImplTest method getSchemaChangeLogs_shouldFailOnDuplicateId.

@Test(expected = IllegalStateException.class)
public void getSchemaChangeLogs_shouldFailOnDuplicateId() {
    // Given
    final int numSchemaChangeLogs = random.nextInt(100) + 1;
    final List<SchemaChangeLog> schemaChangeLogs = new ArrayList<>();
    int order = 1;
    for (int i = 0; i < numSchemaChangeLogs; i++) {
        schemaChangeLogs.add(newSchemaChangeLog("id" + order, order));
        order++;
    }
    // add duplicate element
    final String duplicateId = "id" + (random.nextInt(numSchemaChangeLogs) + 1);
    schemaChangeLogs.add(newSchemaChangeLog(duplicateId, order));
    when(schemaChangeLogDao.getChangeLogs(anyString())).thenReturn(schemaChangeLogs);
    // When
    schemaChangeLogService.getSchemaChangeLogs("namespace");
    // Then
    Assert.fail();
}
Also used : ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog) Test(org.junit.Test)

Example 14 with SchemaChangeLog

use of com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog in project pinpoint by naver.

the class SchemaChangeLogServiceImplTest method recordChangeSet.

@Test
public void recordChangeSet() {
    // Given
    final ChangeSet changeSet = newChangeSet("id1");
    doNothing().when(schemaChangeLogDao).insertChangeLog(anyString(), any(SchemaChangeLog.class));
    // When
    SchemaChangeLog schemaChangeLog = schemaChangeLogService.recordChangeSet("namespace", changeSet);
    // Then
    MatcherAssert.assertThat(schemaChangeLog.getId(), equalTo(changeSet.getId()));
    MatcherAssert.assertThat(schemaChangeLog.getExecOrder(), equalTo(1));
}
Also used : ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog) Test(org.junit.Test)

Example 15 with SchemaChangeLog

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

Aggregations

SchemaChangeLog (com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog)29 ChangeSet (com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet)23 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 HbaseSchemaStatus (com.navercorp.pinpoint.hbase.schema.core.HbaseSchemaStatus)3 ChangeSetManager (com.navercorp.pinpoint.hbase.schema.core.ChangeSetManager)1 CheckSum (com.navercorp.pinpoint.hbase.schema.core.CheckSum)1 HbaseSchemaCommandManager (com.navercorp.pinpoint.hbase.schema.core.command.HbaseSchemaCommandManager)1 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1