Search in sources :

Example 1 with TestAtlasDbServices

use of com.palantir.atlasdb.services.test.TestAtlasDbServices in project atlasdb by palantir.

the class TestTimestampCommand method runAndVerifyCli.

private void runAndVerifyCli(Verifier verifier) throws Exception {
    try (SingleBackendCliTestRunner runner = makeRunner(cliArgs.toArray(new String[0]))) {
        TestAtlasDbServices services = runner.connect(moduleFactory);
        LockService lockService = services.getLockService();
        TimestampService tss = services.getTimestampService();
        LockClient client = services.getTestLockClient();
        Clock clock = GlobalClock.create(lockService);
        long prePunch = clock.getTimeMillis();
        punch(services, tss, clock);
        long postPunch = clock.getTimeMillis();
        long immutableTs = tss.getFreshTimestamp();
        LockRequest request = LockRequest.builder(ImmutableSortedMap.of(lock, LockMode.WRITE)).withLockedInVersionId(immutableTs).doNotBlock().build();
        LockRefreshToken token = lockService.lock(client.getClientId(), request);
        long lastFreshTs = tss.getFreshTimestamps(1000).getUpperBound();
        verifier.verify(runner, tss, immutableTs, prePunch, postPunch, lastFreshTs, true);
        lockService.unlock(token);
        lastFreshTs = tss.getFreshTimestamps(1000).getUpperBound();
        // there are no locks so we now expect immutable to just be a fresh
        runner.freshCommand();
        verifier.verify(runner, tss, immutableTs, prePunch, postPunch, lastFreshTs, false);
    }
}
Also used : LockService(com.palantir.lock.LockService) LockClient(com.palantir.lock.LockClient) SingleBackendCliTestRunner(com.palantir.atlasdb.cli.runner.SingleBackendCliTestRunner) DaggerTestAtlasDbServices(com.palantir.atlasdb.services.test.DaggerTestAtlasDbServices) TestAtlasDbServices(com.palantir.atlasdb.services.test.TestAtlasDbServices) GlobalClock(com.palantir.atlasdb.cleaner.GlobalClock) Clock(com.palantir.common.time.Clock) LockRequest(com.palantir.lock.LockRequest) TimestampService(com.palantir.timestamp.TimestampService) LockRefreshToken(com.palantir.lock.LockRefreshToken)

Example 2 with TestAtlasDbServices

use of com.palantir.atlasdb.services.test.TestAtlasDbServices in project atlasdb by palantir.

the class TestSweepCommand method testSweepAll.

@Test
public void testSweepAll() throws Exception {
    try (SingleBackendCliTestRunner runner = makeRunner(paramsWithDryRunSet(SWEEP_COMMAND, "-a"))) {
        TestAtlasDbServices services = runner.connect(moduleFactory);
        SerializableTransactionManager txm = services.getTransactionManager();
        TimestampService tss = services.getTimestampService();
        KeyValueService kvs = services.getKeyValueService();
        createTable(kvs, TABLE_ONE, TableMetadataPersistence.SweepStrategy.CONSERVATIVE);
        createTable(kvs, TABLE_TWO, TableMetadataPersistence.SweepStrategy.CONSERVATIVE);
        createTable(kvs, TABLE_THREE, TableMetadataPersistence.SweepStrategy.CONSERVATIVE);
        long ts1 = put(txm, TABLE_ONE, "foo", "bar");
        long ts2 = put(txm, TABLE_TWO, "foo", "tar");
        long ts3 = put(txm, TABLE_THREE, "foo", "jar");
        long ts4 = put(txm, TABLE_ONE, "foo", "baz");
        long ts5 = put(txm, TABLE_THREE, "foo", "jaz");
        long ts6 = put(txm, TABLE_TWO, "foo", "taz");
        long ts7 = tss.getFreshTimestamp();
        sweep(runner, ts7);
        Assert.assertEquals("baz", get(kvs, TABLE_ONE, "foo", ts7));
        Assert.assertEquals(deletedValue("bar"), get(kvs, TABLE_ONE, "foo", mid(ts1, ts2)));
        Assert.assertEquals(ImmutableSet.of(deletedTimestamp(ts1), ts4), getAllTs(kvs, TABLE_ONE, "foo"));
        Assert.assertEquals("taz", get(kvs, TABLE_TWO, "foo", ts7));
        Assert.assertEquals(deletedValue("tar"), get(kvs, TABLE_TWO, "foo", mid(ts4, ts6)));
        Assert.assertEquals(ImmutableSet.of(deletedTimestamp(ts2), ts6), getAllTs(kvs, TABLE_TWO, "foo"));
        Assert.assertEquals("jaz", get(kvs, TABLE_THREE, "foo", ts7));
        Assert.assertEquals(deletedValue("jar"), get(kvs, TABLE_THREE, "foo", mid(ts3, ts5)));
        Assert.assertEquals(ImmutableSet.of(deletedTimestamp(ts3), ts5), getAllTs(kvs, TABLE_THREE, "foo"));
    }
}
Also used : KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) SingleBackendCliTestRunner(com.palantir.atlasdb.cli.runner.SingleBackendCliTestRunner) SerializableTransactionManager(com.palantir.atlasdb.transaction.impl.SerializableTransactionManager) DaggerTestAtlasDbServices(com.palantir.atlasdb.services.test.DaggerTestAtlasDbServices) TestAtlasDbServices(com.palantir.atlasdb.services.test.TestAtlasDbServices) TimestampService(com.palantir.timestamp.TimestampService) Test(org.junit.Test)

Example 3 with TestAtlasDbServices

use of com.palantir.atlasdb.services.test.TestAtlasDbServices in project atlasdb by palantir.

the class TestSweepCommand method setup.

@BeforeClass
public static void setup() throws Exception {
    sweepTimestamp = new AtomicLong();
    moduleFactory = new AtlasDbServicesFactory() {

        @Override
        public TestAtlasDbServices connect(ServicesConfigModule servicesConfigModule) {
            return DaggerTestAtlasDbServices.builder().servicesConfigModule(servicesConfigModule).testSweeperModule(TestSweeperModule.create(sweepTimestamp::get)).build();
        }
    };
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) AtlasDbServicesFactory(com.palantir.atlasdb.services.AtlasDbServicesFactory) ServicesConfigModule(com.palantir.atlasdb.services.ServicesConfigModule) DaggerTestAtlasDbServices(com.palantir.atlasdb.services.test.DaggerTestAtlasDbServices) TestAtlasDbServices(com.palantir.atlasdb.services.test.TestAtlasDbServices) BeforeClass(org.junit.BeforeClass)

Example 4 with TestAtlasDbServices

use of com.palantir.atlasdb.services.test.TestAtlasDbServices in project atlasdb by palantir.

the class TestSweepCommand method testSweepNonExistingTable.

@Test
public void testSweepNonExistingTable() throws Exception {
    try (SingleBackendCliTestRunner runner = makeRunner(paramsWithDryRunSet(SWEEP_COMMAND, "-t", NON_EXISTING_TABLE.getQualifiedName()))) {
        TestAtlasDbServices services = runner.connect(moduleFactory);
        long ts5 = services.getTimestampService().getFreshTimestamp();
        String stdout = sweep(runner, ts5);
        Assert.assertFalse(stdout.contains("Swept from"));
        Assert.assertTrue(stdout.contains(String.format("The table %s passed in to sweep does not exist", NON_EXISTING_TABLE)));
    }
}
Also used : SingleBackendCliTestRunner(com.palantir.atlasdb.cli.runner.SingleBackendCliTestRunner) DaggerTestAtlasDbServices(com.palantir.atlasdb.services.test.DaggerTestAtlasDbServices) TestAtlasDbServices(com.palantir.atlasdb.services.test.TestAtlasDbServices) Test(org.junit.Test)

Example 5 with TestAtlasDbServices

use of com.palantir.atlasdb.services.test.TestAtlasDbServices in project atlasdb by palantir.

the class TestSweepCommand method testSweepNamespace.

@Test
public void testSweepNamespace() throws Exception {
    try (SingleBackendCliTestRunner runner = makeRunner(paramsWithDryRunSet(SWEEP_COMMAND, "-n", NS1.getName()))) {
        TestAtlasDbServices services = runner.connect(moduleFactory);
        SerializableTransactionManager txm = services.getTransactionManager();
        TimestampService tss = services.getTimestampService();
        KeyValueService kvs = services.getKeyValueService();
        createTable(kvs, TABLE_ONE, TableMetadataPersistence.SweepStrategy.CONSERVATIVE);
        createTable(kvs, TABLE_TWO, TableMetadataPersistence.SweepStrategy.CONSERVATIVE);
        createTable(kvs, TABLE_THREE, TableMetadataPersistence.SweepStrategy.CONSERVATIVE);
        long ts1 = put(txm, TABLE_ONE, "foo", "bar");
        long ts2 = put(txm, TABLE_TWO, "foo", "tar");
        long ts3 = put(txm, TABLE_THREE, "foo", "jar");
        long ts4 = put(txm, TABLE_ONE, "foo", "baz");
        long ts5 = put(txm, TABLE_THREE, "foo", "jaz");
        long ts6 = put(txm, TABLE_TWO, "foo", "taz");
        long ts7 = tss.getFreshTimestamp();
        sweep(runner, ts7);
        Assert.assertEquals("baz", get(kvs, TABLE_ONE, "foo", ts7));
        Assert.assertEquals(deletedValue("bar"), get(kvs, TABLE_ONE, "foo", mid(ts1, ts2)));
        Assert.assertEquals(ImmutableSet.of(deletedTimestamp(ts1), ts4), getAllTs(kvs, TABLE_ONE, "foo"));
        Assert.assertEquals("taz", get(kvs, TABLE_TWO, "foo", ts7));
        Assert.assertEquals(deletedValue("tar"), get(kvs, TABLE_TWO, "foo", mid(ts4, ts6)));
        Assert.assertEquals(ImmutableSet.of(deletedTimestamp(ts2), ts6), getAllTs(kvs, TABLE_TWO, "foo"));
        Assert.assertEquals("jaz", get(kvs, TABLE_THREE, "foo", ts7));
        Assert.assertEquals("jar", get(kvs, TABLE_THREE, "foo", mid(ts3, ts5)));
        Assert.assertEquals(ImmutableSet.of(ts3, ts5), getAllTs(kvs, TABLE_THREE, "foo"));
    }
}
Also used : KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) SingleBackendCliTestRunner(com.palantir.atlasdb.cli.runner.SingleBackendCliTestRunner) SerializableTransactionManager(com.palantir.atlasdb.transaction.impl.SerializableTransactionManager) DaggerTestAtlasDbServices(com.palantir.atlasdb.services.test.DaggerTestAtlasDbServices) TestAtlasDbServices(com.palantir.atlasdb.services.test.TestAtlasDbServices) TimestampService(com.palantir.timestamp.TimestampService) Test(org.junit.Test)

Aggregations

DaggerTestAtlasDbServices (com.palantir.atlasdb.services.test.DaggerTestAtlasDbServices)8 TestAtlasDbServices (com.palantir.atlasdb.services.test.TestAtlasDbServices)8 SingleBackendCliTestRunner (com.palantir.atlasdb.cli.runner.SingleBackendCliTestRunner)6 TimestampService (com.palantir.timestamp.TimestampService)5 Test (org.junit.Test)5 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)4 SerializableTransactionManager (com.palantir.atlasdb.transaction.impl.SerializableTransactionManager)4 AtlasDbServicesFactory (com.palantir.atlasdb.services.AtlasDbServicesFactory)2 ServicesConfigModule (com.palantir.atlasdb.services.ServicesConfigModule)2 BeforeClass (org.junit.BeforeClass)2 GlobalClock (com.palantir.atlasdb.cleaner.GlobalClock)1 Clock (com.palantir.common.time.Clock)1 LockClient (com.palantir.lock.LockClient)1 LockRefreshToken (com.palantir.lock.LockRefreshToken)1 LockRequest (com.palantir.lock.LockRequest)1 LockService (com.palantir.lock.LockService)1 Scanner (java.util.Scanner)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1