@Override void testSetup(CassandraKeyValueService kvs) { kvs.createTable(TEST_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA); kvs.createTable(TEST_TABLE_2, AtlasDbConstants.EMPTY_TABLE_METADATA); kvs.createTable(TEST_TABLE_3, AtlasDbConstants.EMPTY_TABLE_METADATA); }
private CassandraClientPool clientPool() { return cassandraKeyValueService.getClientPool(); }
private static boolean canCreateCassandraKeyValueService() { return CassandraKeyValueServiceImpl.createForTesting( KVS_CONFIG, LEADER_CONFIG) .isInitialized(); } }
@Override void testSetup(CassandraKeyValueService kvs) { kvs.createTable(TEST_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA); kvs.putUnlessExists(TEST_TABLE, ImmutableMap.of(NONEMPTY_CELL, CONTENTS)); }
@Test(timeout = 10 * 1000) public void testTableCreationCanOccurAfterError() { try { kvs.createTable(BAD_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA); } catch (Exception e) { // failure expected } kvs.createTable(GOOD_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA); kvs.dropTable(GOOD_TABLE); }
@Override void testSetup(CassandraKeyValueService kvs) { kvs.createTable(TEST_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA); kvs.put(TEST_TABLE, ImmutableMap.of(CELL_1_1, PtBytes.toBytes("old_value")), TIMESTAMP - 1); kvs.put(TEST_TABLE, ImmutableMap.of(CELL_1_1, CONTENTS), TIMESTAMP); kvs.put(TEST_TABLE, ImmutableMap.of(CELL_1_2, CONTENTS), TIMESTAMP); kvs.put(TEST_TABLE, ImmutableMap.of(CELL_2_1, CONTENTS), TIMESTAMP); }
kvs.createTable(missingMetadataTable, initialMetadata); byte[] existingMetadata = kvs.getMetadataForTable(missingMetadataTable); assertThat(initialMetadata, is(existingMetadata)); "m".getBytes(StandardCharsets.UTF_8)); Value persistedMetadata = Iterables.getLast( kvs.get(AtlasDbConstants.DEFAULT_METADATA_TABLE, ImmutableMap.of(cell, Long.MAX_VALUE)).values()); kvs.delete(AtlasDbConstants.DEFAULT_METADATA_TABLE, ImmutableMultimap.of(cell, persistedMetadata.getTimestamp())); kvs.createTable(missingMetadataTable, initialMetadata); existingMetadata = kvs.getMetadataForTable(missingMetadataTable); assertThat(initialMetadata, is(existingMetadata));
@Test public void ifWrapperIsNotInitializedDelegateIsNotCalled() { when(kvsWrapper.isInitialized()).thenReturn(false); TableReference tableRef = TableReference.create(Namespace.DEFAULT_NAMESPACE, "test"); assertThatThrownBy(() -> kvsWrapper.createTable(tableRef, AtlasDbConstants.GENERIC_TABLE_METADATA)) .isInstanceOf(NotInitializedException.class); verify(kvs, never()).createTable(any(TableReference.class), any()); } }
@Test public void testGetMetadataCaseInsensitive() { // Make two casewise-different references to the "same" table TableReference caseSensitiveTable = TableReference.createFromFullyQualifiedName("test.cased_table"); TableReference wackyCasedTable = TableReference.createFromFullyQualifiedName("test.CaSeD_TaBlE"); byte[] initialMetadata = new TableDefinition() { { rowName(); rowComponent("blob", ValueType.BLOB); columns(); column("bar", "b", ValueType.BLOB); conflictHandler(ConflictHandler.IGNORE_ALL); sweepStrategy(TableMetadataPersistence.SweepStrategy.NOTHING); } }.toTableMetadata().persistToBytes(); kvs.createTable(caseSensitiveTable, initialMetadata); // retrieve the metadata and see that it's the same as what we just put in byte[] existingMetadata = kvs.getMetadataForTable(caseSensitiveTable); assertThat(initialMetadata, is(existingMetadata)); // retrieve same metadata with a wacky cased version of the "same" name existingMetadata = kvs.getMetadataForTable(wackyCasedTable); assertThat(initialMetadata, is(existingMetadata)); kvs.dropTable(caseSensitiveTable); }
@Before public void setUp() { kv.createTable(AtlasDbConstants.TIMESTAMP_TABLE, CassandraTimestampUtils.TIMESTAMP_TABLE_METADATA.persistToBytes()); kv.truncateTable(AtlasDbConstants.TIMESTAMP_TABLE); }
@Test public void canCreateTable() { TableReference tableToCreate = TableReference.createWithEmptyNamespace("new_table"); getTestKvs().createTable(tableToCreate, AtlasDbConstants.GENERIC_TABLE_METADATA); assertThat(getTestKvs().getAllTableNames()).contains(tableToCreate); assertKvsReturnsGenericMetadata(tableToCreate); assertCassandraSchemaChanged(); }
@Test @SuppressWarnings("Slf4jConstantLogMessage") public void testGcGraceSecondsUpgradeIsApplied() throws TException { Logger testLogger = mock(Logger.class); //nth startup CassandraKeyValueService kvs = createKvs(getConfigWithGcGraceSeconds(FOUR_DAYS_IN_SECONDS), testLogger); kvs.createTable(NEVER_SEEN, AtlasDbConstants.GENERIC_TABLE_METADATA); assertThatGcGraceSecondsIs(kvs, FOUR_DAYS_IN_SECONDS); kvs.close(); CassandraKeyValueService kvs2 = createKvs(getConfigWithGcGraceSeconds(ONE_HOUR_IN_SECONDS), testLogger); assertThatGcGraceSecondsIs(kvs2, ONE_HOUR_IN_SECONDS); kvs2.close(); //n+1th startup with different GC grace seconds - should upgrade verify(testLogger, times(1)) .info(startsWith("New table-related settings were applied on startup!!")); CassandraKeyValueService kvs3 = createKvs(getConfigWithGcGraceSeconds(ONE_HOUR_IN_SECONDS), testLogger); assertThatGcGraceSecondsIs(kvs3, ONE_HOUR_IN_SECONDS); //startup with same gc grace seconds as previous one - no upgrade verify(testLogger, times(2)) .info(startsWith("No tables are being upgraded on startup. No updated table-related settings found.")); kvs3.close(); }
@Test public void backupThrowsIfTimestampTableDoesNotExist() { kv.dropTable(AtlasDbConstants.TIMESTAMP_TABLE); assertThatThrownBy(backupRunner::backupExistingTimestamp).isInstanceOf(IllegalStateException.class); }
@Test public void putUnlessExistsThrowsOnExists() { byte[] newContents = PtBytes.toBytes("new_value"); assertThatThrownBy(() -> getTestKvs().putUnlessExists(TEST_TABLE, ImmutableMap.of(NONEMPTY_CELL, newContents))) .isInstanceOf(KeyAlreadyExistsException.class); Map<Cell, Value> result = getTestKvs() .get(TEST_TABLE, ImmutableMap.of(NONEMPTY_CELL, AtlasDbConstants.TRANSACTION_TS)); assertThat(result.get(NONEMPTY_CELL)).isNotEqualTo(Value.create(newContents, AtlasDbConstants.TRANSACTION_TS)); }
@Test public void canPut() { getTestKvs().put(TEST_TABLE, ImmutableMap.of(CELL_1_1, CONTENTS), TIMESTAMP); assertLatestValueInCell(CELL_1_1, VALUE); }
private void assertLatestValueInCellEquals(Cell cell, Value value) { Map<Cell, Value> result = getTestKvs().get(TEST_TABLE, ImmutableMap.of(cell, Long.MAX_VALUE)); assertThat(result.get(cell)).isEqualTo(value); } }
void assertKvsReturnsEmptyMetadata(TableReference tableRef) { assertThat(getTestKvs().getMetadataForTable(tableRef)).isEqualTo(AtlasDbConstants.EMPTY_TABLE_METADATA); }
private void checkTimestampTableExists() { CassandraTables cassandraTables = cassandraKeyValueService.getCassandraTables(); Preconditions.checkState( cassandraTables.getExisting().contains(AtlasDbConstants.TIMESTAMP_TABLE.getQualifiedName()), "[BACKUP/RESTORE] Tried to get timestamp bound data when the timestamp table didn't exist!"); }
private TracingQueryRunner queryRunner() { return cassandraKeyValueService.getTracingQueryRunner(); }
@Test public void deletingThrows() { assertThrowsAtlasDbDependencyExceptionAndDoesNotChangeCassandraSchema(() -> getTestKvs().delete(TEST_TABLE, ImmutableMultimap.of(CELL_1_1, TIMESTAMP))); }