Search in sources :

Example 41 with Assert.assertEquals

use of org.junit.Assert.assertEquals in project pravega by pravega.

the class ZkStreamTest method testTransaction.

@Test(timeout = 10000)
public void testTransaction() throws Exception {
    final ScalingPolicy policy = ScalingPolicy.fixed(5);
    final StreamMetadataStore store = new ZKStreamMetadataStore(cli, executor);
    final String streamName = "testTx";
    store.createScope(SCOPE).get();
    final Predicate<Throwable> operationNotAllowedPredicate = ex -> Exceptions.unwrap(ex) instanceof StoreException.IllegalStateException;
    StreamConfiguration streamConfig = StreamConfiguration.builder().scope(SCOPE).streamName(streamName).scalingPolicy(policy).build();
    store.createStream(SCOPE, streamName, streamConfig, System.currentTimeMillis(), null, executor).get();
    store.setState(SCOPE, streamName, State.ACTIVE, null, executor).get();
    OperationContext context = store.createContext(ZkStreamTest.SCOPE, streamName);
    UUID txnId1 = UUID.randomUUID();
    VersionedTransactionData tx = store.createTransaction(SCOPE, streamName, txnId1, 10000, 600000, 30000, context, executor).get();
    Assert.assertEquals(txnId1, tx.getId());
    UUID txnId2 = UUID.randomUUID();
    VersionedTransactionData tx2 = store.createTransaction(SCOPE, streamName, txnId2, 10000, 600000, 30000, context, executor).get();
    Assert.assertEquals(txnId2, tx2.getId());
    store.sealTransaction(SCOPE, streamName, tx.getId(), true, Optional.<Integer>empty(), context, executor).get();
    assert store.transactionStatus(SCOPE, streamName, tx.getId(), context, executor).get().equals(TxnStatus.COMMITTING);
    // Test to ensure that sealTransaction is idempotent.
    Assert.assertEquals(TxnStatus.COMMITTING, store.sealTransaction(SCOPE, streamName, tx.getId(), true, Optional.empty(), context, executor).join().getKey());
    // Test to ensure that COMMITTING transaction cannot be aborted.
    testAbortFailure(store, SCOPE, streamName, tx.getEpoch(), tx.getId(), context, operationNotAllowedPredicate);
    CompletableFuture<TxnStatus> f1 = store.commitTransaction(SCOPE, streamName, tx.getEpoch(), tx.getId(), context, executor);
    store.sealTransaction(SCOPE, streamName, tx2.getId(), false, Optional.<Integer>empty(), context, executor).get();
    assert store.transactionStatus(SCOPE, streamName, tx2.getId(), context, executor).get().equals(TxnStatus.ABORTING);
    // Test to ensure that sealTransaction is idempotent.
    Assert.assertEquals(TxnStatus.ABORTING, store.sealTransaction(SCOPE, streamName, tx2.getId(), false, Optional.empty(), context, executor).join().getKey());
    // Test to ensure that ABORTING transaction cannot be committed.
    testCommitFailure(store, SCOPE, streamName, tx2.getEpoch(), tx2.getId(), context, operationNotAllowedPredicate);
    CompletableFuture<TxnStatus> f2 = store.abortTransaction(SCOPE, streamName, tx2.getEpoch(), tx2.getId(), context, executor);
    CompletableFuture.allOf(f1, f2).get();
    assert store.transactionStatus(SCOPE, streamName, tx.getId(), context, executor).get().equals(TxnStatus.COMMITTED);
    assert store.transactionStatus(SCOPE, streamName, tx2.getId(), context, executor).get().equals(TxnStatus.ABORTED);
    // Test to ensure that sealTransaction, to commit it, on committed transaction does not throw an error.
    Assert.assertEquals(TxnStatus.COMMITTED, store.sealTransaction(SCOPE, streamName, tx.getId(), true, Optional.empty(), context, executor).join().getKey());
    // Test to ensure that commitTransaction is idempotent.
    Assert.assertEquals(TxnStatus.COMMITTED, store.commitTransaction(SCOPE, streamName, tx.getEpoch(), tx.getId(), context, executor).join());
    // Test to ensure that sealTransaction, to abort it, and abortTransaction on committed transaction throws error.
    testAbortFailure(store, SCOPE, streamName, tx.getEpoch(), tx.getId(), context, operationNotAllowedPredicate);
    // Test to ensure that sealTransaction, to abort it, on aborted transaction does not throw an error.
    Assert.assertEquals(TxnStatus.ABORTED, store.sealTransaction(SCOPE, streamName, tx2.getId(), false, Optional.empty(), context, executor).join().getKey());
    // Test to ensure that abortTransaction is idempotent.
    Assert.assertEquals(TxnStatus.ABORTED, store.abortTransaction(SCOPE, streamName, tx2.getEpoch(), tx2.getId(), context, executor).join());
    // Test to ensure that sealTransaction, to abort it, and abortTransaction on committed transaction throws error.
    testCommitFailure(store, SCOPE, streamName, tx2.getEpoch(), tx2.getId(), context, operationNotAllowedPredicate);
    assert store.commitTransaction(ZkStreamTest.SCOPE, streamName, 0, UUID.randomUUID(), null, executor).handle((ok, ex) -> {
        if (ex.getCause() instanceof StoreException.DataNotFoundException) {
            return true;
        } else {
            throw new RuntimeException("assert failed");
        }
    }).get();
    assert store.abortTransaction(ZkStreamTest.SCOPE, streamName, 0, UUID.randomUUID(), null, executor).handle((ok, ex) -> {
        if (ex.getCause() instanceof StoreException.DataNotFoundException) {
            return true;
        } else {
            throw new RuntimeException("assert failed");
        }
    }).get();
    assert store.transactionStatus(ZkStreamTest.SCOPE, streamName, UUID.randomUUID(), context, executor).get().equals(TxnStatus.UNKNOWN);
}
Also used : CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) Arrays(java.util.Arrays) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) AssertExtensions(io.pravega.test.common.AssertExtensions) Exceptions(io.pravega.common.Exceptions) CompletableFuture(java.util.concurrent.CompletableFuture) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ArrayList(java.util.ArrayList) RetryOneTime(org.apache.curator.retry.RetryOneTime) Lists(com.google.common.collect.Lists) TestingServerStarter(io.pravega.test.common.TestingServerStarter) After(org.junit.After) Map(java.util.Map) TestingServer(org.apache.curator.test.TestingServer) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) DeleteScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus) Before(org.junit.Before) Predicate(java.util.function.Predicate) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) State(io.pravega.controller.store.stream.tables.State) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ExecutionException(java.util.concurrent.ExecutionException) Mockito(org.mockito.Mockito) AbstractMap(java.util.AbstractMap) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) Assert(org.junit.Assert) Collections(java.util.Collections) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Assert.assertEquals(org.junit.Assert.assertEquals) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) UUID(java.util.UUID) Test(org.junit.Test)

Example 42 with Assert.assertEquals

use of org.junit.Assert.assertEquals in project graal by oracle.

the class SLExceptionTest method assertException.

private void assertException(boolean failImmediately, String source, String... expectedFrames) {
    boolean initialExecute = true;
    try {
        Value value = ctx.eval("sl", source);
        initialExecute = false;
        if (failImmediately) {
            Assert.fail("Should not reach here.");
        }
        ProxyExecutable proxy = (args) -> args[0].execute();
        value.execute(proxy);
        Assert.fail("Should not reach here.");
    } catch (PolyglotException e) {
        Assert.assertEquals(failImmediately, initialExecute);
        assertFrames(failImmediately, e, expectedFrames);
    }
}
Also used : Iterator(java.util.Iterator) PolyglotException(org.graalvm.polyglot.PolyglotException) Assert.assertNotNull(org.junit.Assert.assertNotNull) Value(org.graalvm.polyglot.Value) Assert.assertNotSame(org.junit.Assert.assertNotSame) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) StackFrame(org.graalvm.polyglot.PolyglotException.StackFrame) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ArrayList(java.util.ArrayList) Assert.assertSame(org.junit.Assert.assertSame) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) Source(org.graalvm.polyglot.Source) After(org.junit.After) ProxyExecutable(org.graalvm.polyglot.proxy.ProxyExecutable) Assert.fail(org.junit.Assert.fail) Context(org.graalvm.polyglot.Context) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) ProxyExecutable(org.graalvm.polyglot.proxy.ProxyExecutable) Value(org.graalvm.polyglot.Value) PolyglotException(org.graalvm.polyglot.PolyglotException)

Example 43 with Assert.assertEquals

use of org.junit.Assert.assertEquals in project graal by oracle.

the class MultiThreadedLanguageTest method testAccessTruffleContextFromExclusivePolyglotThread.

@Test
public void testAccessTruffleContextFromExclusivePolyglotThread() throws Throwable {
    // don't allow multi-threading in this test as every context
    // is used exclusively by one thread.
    MultiThreadedLanguage.isThreadAccessAllowed = (req) -> {
        return req.singleThreaded;
    };
    final int iterations = 10;
    final int innerIterations = 10;
    AtomicReference<Throwable> lastError = new AtomicReference<>();
    UncaughtExceptionHandler uncaughtHandler = (run, e) -> lastError.set(e);
    Context polyglotContext = Context.newBuilder().allowCreateThread(true).build();
    ConcurrentHashMap<LanguageContext, String> seenContexts = new ConcurrentHashMap<>();
    eval(polyglotContext, new Function<Env, Object>() {

        @SuppressWarnings("hiding")
        public Object apply(Env env) {
            List<Thread> threads = new ArrayList<>();
            List<TruffleContext> contexts = new ArrayList<>();
            for (int i = 0; i < iterations; i++) {
                TruffleContext context = env.newContextBuilder().build();
                Thread thread = env.createThread(() -> {
                    assertUniqueContext();
                    List<Thread> innerThreads = new ArrayList<>();
                    List<TruffleContext> innerContexts = new ArrayList<>();
                    for (int j = 0; j < innerIterations; j++) {
                        TruffleContext innerContext = env.newContextBuilder().build();
                        Thread innerThread = env.createThread(() -> {
                            assertUniqueContext();
                        }, innerContext);
                        innerThread.setUncaughtExceptionHandler(uncaughtHandler);
                        innerThread.start();
                        innerThreads.add(innerThread);
                        innerContexts.add(innerContext);
                    }
                    for (Thread innerThread : innerThreads) {
                        try {
                            innerThread.join();
                        } catch (InterruptedException e) {
                        }
                    }
                    for (TruffleContext innerContext : innerContexts) {
                        innerContext.close();
                    }
                }, context);
                thread.setUncaughtExceptionHandler(uncaughtHandler);
                thread.start();
                threads.add(thread);
                contexts.add(context);
            }
            for (Thread thread : threads) {
                try {
                    thread.join();
                } catch (InterruptedException e) {
                }
            }
            for (TruffleContext context : contexts) {
                context.close();
            }
            return null;
        }

        private LanguageContext assertUniqueContext() {
            LanguageContext languageContext = MultiThreadedLanguage.getContext();
            Assert.assertNotNull(languageContext);
            Assert.assertFalse(seenContexts.containsKey(languageContext));
            seenContexts.put(languageContext, "");
            return languageContext;
        }
    });
    Assert.assertEquals(221, initializeCount.get());
    Assert.assertEquals(initializeCount.get() - 1, disposeCount.get());
    Assert.assertEquals(0, initializeMultiThreadingCount.get());
    // Test that the same context is available in threads when created with Env.getContext()
    MultiThreadedLanguage.isThreadAccessAllowed = (req) -> {
        return true;
    };
    eval(polyglotContext, new Function<Env, Object>() {

        @SuppressWarnings("hiding")
        public Object apply(Env env) {
            List<Thread> threads = new ArrayList<>();
            LanguageContext languageContext = MultiThreadedLanguage.getContext();
            for (int i = 0; i < iterations; i++) {
                Thread thread = env.createThread(() -> {
                    LanguageContext threadContext = MultiThreadedLanguage.getContext();
                    assertSame(languageContext, threadContext);
                    List<Thread> innerThreads = new ArrayList<>();
                    List<TruffleContext> innerContexts = new ArrayList<>();
                    for (int j = 0; j < innerIterations; j++) {
                        Thread innerThread = env.createThread(() -> {
                            LanguageContext innerThreadContext = MultiThreadedLanguage.getContext();
                            assertSame(languageContext, innerThreadContext);
                        }, env.getContext());
                        innerThread.setUncaughtExceptionHandler(uncaughtHandler);
                        innerThread.start();
                        innerThreads.add(innerThread);
                    }
                    for (Thread innerThread : innerThreads) {
                        try {
                            innerThread.join();
                        } catch (InterruptedException e) {
                        }
                    }
                    for (TruffleContext innerContext : innerContexts) {
                        innerContext.close();
                    }
                }, env.getContext());
                thread.setUncaughtExceptionHandler(uncaughtHandler);
                thread.start();
                threads.add(thread);
            }
            for (Thread thread : threads) {
                try {
                    thread.join();
                } catch (InterruptedException e) {
                }
            }
            return null;
        }
    });
    if (lastError.get() != null) {
        throw lastError.get();
    }
    polyglotContext.close();
    Assert.assertEquals(331, initializeCount.get());
    Assert.assertEquals(initializeCount.get(), disposeCount.get());
    Assert.assertEquals(1, initializeMultiThreadingCount.get());
}
Also used : ThreadRequest(com.oracle.truffle.api.test.polyglot.MultiThreadedLanguage.ThreadRequest) UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) PolyglotException(org.graalvm.polyglot.PolyglotException) Env(com.oracle.truffle.api.TruffleLanguage.Env) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Assert.assertSame(org.junit.Assert.assertSame) HashSet(java.util.HashSet) Future(java.util.concurrent.Future) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) After(org.junit.After) Assert.fail(org.junit.Assert.fail) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) Assert.assertNotNull(org.junit.Assert.assertNotNull) Semaphore(java.util.concurrent.Semaphore) Value(org.graalvm.polyglot.Value) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) Executors(java.util.concurrent.Executors) TruffleContext(com.oracle.truffle.api.TruffleContext) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Engine(org.graalvm.polyglot.Engine) Entry(java.util.Map.Entry) Context(org.graalvm.polyglot.Context) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) LanguageContext(com.oracle.truffle.api.test.polyglot.MultiThreadedLanguage.LanguageContext) TruffleContext(com.oracle.truffle.api.TruffleContext) Context(org.graalvm.polyglot.Context) LanguageContext(com.oracle.truffle.api.test.polyglot.MultiThreadedLanguage.LanguageContext) TruffleContext(com.oracle.truffle.api.TruffleContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) LanguageContext(com.oracle.truffle.api.test.polyglot.MultiThreadedLanguage.LanguageContext) Env(com.oracle.truffle.api.TruffleLanguage.Env) ArrayList(java.util.ArrayList) List(java.util.List) UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 44 with Assert.assertEquals

use of org.junit.Assert.assertEquals in project rdf2neo by Rothamsted.

the class CypherHandlersIT method testRelations.

/**
 * Tests {@link CyRelationLoadingHandler} to see if relations are mapped from RDF and loaded into Neo4J.
 */
@Test
public void testRelations() throws Exception {
    try (Driver neoDriver = GraphDatabase.driver("bolt://127.0.0.1:7687", AuthTokens.basic("neo4j", "test"));
        CyRelationLoadingHandler handler = new CyRelationLoadingHandler();
        RdfDataManager rdfMgr = new RdfDataManager(RdfDataManagerTest.TDB_PATH);
        Neo4jDataManager neoMgr = new Neo4jDataManager(neoDriver)) {
        handler.setRdfDataManager(rdfMgr);
        handler.setNeo4jDataManager(neoMgr);
        handler.setRelationTypesSparql(RdfDataManagerTest.SPARQL_REL_TYPES);
        handler.setRelationPropsSparql(RdfDataManagerTest.SPARQL_REL_PROPS);
        Set<QuerySolution> relSparqlRows = new HashSet<>();
        Dataset dataSet = rdfMgr.getDataSet();
        Txn.executeRead(dataSet, () -> SparqlUtils.select(RdfDataManagerTest.SPARQL_REL_TYPES, rdfMgr.getDataSet().getDefaultModel()).forEachRemaining(row -> relSparqlRows.add(row)));
        handler.accept(relSparqlRows);
        Session session = neoDriver.session(AccessMode.READ);
        StatementResult cursor = session.run("MATCH ()-[r]->() RETURN COUNT ( r ) AS ct");
        Assert.assertEquals("Wrong count for relations", 3, cursor.next().get("ct").asLong());
        cursor = session.run("MATCH p = (:TestNode{ iri:$iri1 })-[:relatedTo]->(:TestNode{ iri:$iri2 }) RETURN COUNT ( p ) AS ct", parameters("iri1", iri("ex:1"), "iri2", iri("ex:2")));
        Assert.assertEquals("Wrong count for {1 relatedTo 2}!", 1, cursor.next().get("ct").asLong());
        cursor = session.run("MATCH p = (:SuperTestNode{ iri:$iri1 })-[:derivedFrom]->(:TestNode{ iri:$iri2 }) RETURN COUNT ( p ) AS ct", parameters("iri1", iri("ex:3"), "iri2", iri("ex:1")));
        Assert.assertEquals("Wrong count for {3 derivedFrom 1}!", 1, cursor.next().get("ct").asLong());
        cursor = session.run("MATCH (:TestNode{ iri:$iri1 })-[r:relatedTo]->(:AdditionalLabel{ iri:$iri2 }) RETURN r.note AS note", parameters("iri1", iri("ex:2"), "iri2", iri("ex:3")));
        assertTrue("{2 relatedTo 3} not found!", cursor.hasNext());
        Set<String> values = cursor.next().get("note").asList().stream().map(v -> (String) v).collect(Collectors.toSet());
        Set<String> refValues = new HashSet<>(Arrays.asList(new String[] { "Reified Relation", "Another Note" }));
        assertTrue("reified relation, wrong property value for 'note'!", Sets.difference(values, refValues).isEmpty());
    }
}
Also used : SparqlUtils(info.marcobrandizi.rdfutils.jena.SparqlUtils) Arrays(java.util.Arrays) Driver(org.neo4j.driver.v1.Driver) BeforeClass(org.junit.BeforeClass) AccessMode(org.neo4j.driver.v1.AccessMode) LoggerFactory(org.slf4j.LoggerFactory) HashSet(java.util.HashSet) QuerySolution(org.apache.jena.query.QuerySolution) Session(org.neo4j.driver.v1.Session) Txn(org.apache.jena.system.Txn) Values.parameters(org.neo4j.driver.v1.Values.parameters) Resource(org.apache.jena.rdf.model.Resource) Map(java.util.Map) GraphDatabase(org.neo4j.driver.v1.GraphDatabase) NamespaceUtils.iri(info.marcobrandizi.rdfutils.namespaces.NamespaceUtils.iri) Dataset(org.apache.jena.query.Dataset) Before(org.junit.Before) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) AuthTokens(org.neo4j.driver.v1.AuthTokens) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Stream(java.util.stream.Stream) StatementResult(org.neo4j.driver.v1.StatementResult) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) StatementResult(org.neo4j.driver.v1.StatementResult) Dataset(org.apache.jena.query.Dataset) Driver(org.neo4j.driver.v1.Driver) QuerySolution(org.apache.jena.query.QuerySolution) HashSet(java.util.HashSet) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 45 with Assert.assertEquals

use of org.junit.Assert.assertEquals in project atlasdb by palantir.

the class SnapshotTransactionTest method testTransactionAtomicity.

@Test
public void testTransactionAtomicity() throws Exception {
    // This test runs multiple transactions in parallel, with KeyValueService.put calls throwing
    // a RuntimeException from time to time and hanging other times. which effectively kills the
    // thread. We ensure that every transaction either adds 5 rows to the table or adds 0 rows
    // by checking at the end that the number of rows is a multiple of 5.
    final TableReference tableRef = TABLE;
    Random random = new Random(1);
    final UnstableKeyValueService unstableKvs = new UnstableKeyValueService(keyValueService, random);
    final TestTransactionManager unstableTransactionManager = new TestTransactionManagerImpl(unstableKvs, timestampService, lockClient, lockService, transactionService, conflictDetectionManager, sweepStrategyManager, sweepQueue);
    ScheduledExecutorService service = PTExecutors.newScheduledThreadPool(20);
    for (int i = 0; i < 30; i++) {
        final int threadNumber = i;
        service.schedule((Callable<Void>) () -> {
            if (threadNumber == 10) {
                unstableKvs.setRandomlyThrow(true);
            }
            if (threadNumber == 20) {
                unstableKvs.setRandomlyHang(true);
            }
            Transaction transaction = unstableTransactionManager.createNewTransaction();
            BatchingVisitable<RowResult<byte[]>> results = transaction.getRange(tableRef, RangeRequest.builder().build());
            final MutableInt nextIndex = new MutableInt(0);
            results.batchAccept(1, AbortingVisitors.batching((AbortingVisitor<RowResult<byte[]>, Exception>) row -> {
                byte[] dataBytes = row.getColumns().get(PtBytes.toBytes("data"));
                BigInteger dataValue = new BigInteger(dataBytes);
                nextIndex.setValue(Math.max(nextIndex.toInteger(), dataValue.intValue() + 1));
                return true;
            }));
            // rows to the table.
            for (int j = 0; j < 5; j++) {
                int rowNumber = nextIndex.toInteger() + j;
                Cell cell = Cell.create(PtBytes.toBytes("row" + rowNumber), PtBytes.toBytes("data"));
                transaction.put(tableRef, ImmutableMap.of(cell, BigInteger.valueOf(rowNumber).toByteArray()));
                Thread.yield();
            }
            transaction.commit();
            return null;
        }, i * 20, TimeUnit.MILLISECONDS);
    }
    service.shutdown();
    service.awaitTermination(1, TimeUnit.SECONDS);
    // Verify each table has a number of rows that's a multiple of 5
    Transaction verifyTransaction = txManager.createNewTransaction();
    BatchingVisitable<RowResult<byte[]>> results = verifyTransaction.getRange(tableRef, RangeRequest.builder().build());
    final MutableInt numRows = new MutableInt(0);
    results.batchAccept(1, AbortingVisitors.batching((AbortingVisitor<RowResult<byte[]>, Exception>) row -> {
        numRows.increment();
        return true;
    }));
    Assert.assertEquals(0, numRows.toInteger() % 5);
}
Also used : ColumnMetadataDescription(com.palantir.atlasdb.table.description.ColumnMetadataDescription) Matchers.not(org.hamcrest.Matchers.not) Future(java.util.concurrent.Future) Pair(org.apache.commons.lang3.tuple.Pair) MutableLong(org.apache.commons.lang3.mutable.MutableLong) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) BigInteger(java.math.BigInteger) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Set(java.util.Set) LockMode(com.palantir.lock.LockMode) Executors(java.util.concurrent.Executors) Matchers.any(org.mockito.Matchers.any) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Matchers.is(org.hamcrest.Matchers.is) TransactionLockTimeoutNonRetriableException(com.palantir.atlasdb.transaction.api.TransactionLockTimeoutNonRetriableException) Matchers.containsString(org.hamcrest.Matchers.containsString) NoOpCleaner(com.palantir.atlasdb.cleaner.NoOpCleaner) Mockito.mock(org.mockito.Mockito.mock) Joiner(com.google.common.base.Joiner) ColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.ColumnRangeSelection) Iterables(com.google.common.collect.Iterables) ConflictHandler(com.palantir.atlasdb.transaction.api.ConflictHandler) Expectations(org.jmock.Expectations) CachePriority(com.palantir.atlasdb.protos.generated.TableMetadataPersistence.CachePriority) TransactionFailedRetriableException(com.palantir.atlasdb.transaction.api.TransactionFailedRetriableException) Callable(java.util.concurrent.Callable) SimpleTimeDuration(com.palantir.lock.SimpleTimeDuration) AtlasDbTestCase(com.palantir.atlasdb.AtlasDbTestCase) PtBytes(com.palantir.atlasdb.encoding.PtBytes) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) Multimaps(com.google.common.collect.Multimaps) LockAwareTransactionTask(com.palantir.atlasdb.transaction.api.LockAwareTransactionTask) Lists(com.google.common.collect.Lists) LegacyTimelockService(com.palantir.lock.impl.LegacyTimelockService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) AbortingVisitors(com.palantir.common.base.AbortingVisitors) LockRequest(com.palantir.lock.LockRequest) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Before(org.junit.Before) LockCollections(com.palantir.lock.LockCollections) Assert.assertTrue(org.junit.Assert.assertTrue) Throwables(com.google.common.base.Throwables) Test(org.junit.Test) AtlasRowLockDescriptor(com.palantir.lock.AtlasRowLockDescriptor) Mockery(org.jmock.Mockery) ExecutionException(java.util.concurrent.ExecutionException) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) AtomicLong(java.util.concurrent.atomic.AtomicLong) TimeDuration(com.palantir.lock.TimeDuration) Matchers.hasItem(org.hamcrest.Matchers.hasItem) LockService(com.palantir.lock.LockService) LockClient(com.palantir.lock.LockClient) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) MutableInt(org.apache.commons.lang3.mutable.MutableInt) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) Sequence(org.jmock.Sequence) Random(java.util.Random) BatchingVisitable(com.palantir.common.base.BatchingVisitable) CompletionService(java.util.concurrent.CompletionService) Assert.assertThat(org.junit.Assert.assertThat) PTExecutors(com.palantir.common.concurrent.PTExecutors) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Matchers.eq(org.mockito.Matchers.eq) Assert.fail(org.junit.Assert.fail) TrackingKeyValueService(com.palantir.atlasdb.keyvalue.impl.TrackingKeyValueService) LockDescriptor(com.palantir.lock.LockDescriptor) TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TransactionReadSentinelBehavior(com.palantir.atlasdb.transaction.api.TransactionReadSentinelBehavior) Collection(java.util.Collection) SweepStrategy(com.palantir.atlasdb.protos.generated.TableMetadataPersistence.SweepStrategy) Collectors(java.util.stream.Collectors) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) TransactionConflictException(com.palantir.atlasdb.transaction.api.TransactionConflictException) List(java.util.List) MultiDelegateProxy(com.palantir.common.proxy.MultiDelegateProxy) Optional(java.util.Optional) ForwardingKeyValueService(com.palantir.atlasdb.keyvalue.impl.ForwardingKeyValueService) SortedMap(java.util.SortedMap) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) HeldLocksToken(com.palantir.lock.HeldLocksToken) Supplier(com.google.common.base.Supplier) Multimap(com.google.common.collect.Multimap) LockRefreshToken(com.palantir.lock.LockRefreshToken) AtlasDbConstraintCheckingMode(com.palantir.atlasdb.transaction.api.AtlasDbConstraintCheckingMode) ImmutableList(com.google.common.collect.ImmutableList) Suppliers(com.google.common.base.Suppliers) WriteInfo(com.palantir.atlasdb.sweep.queue.WriteInfo) ExecutorService(java.util.concurrent.ExecutorService) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) EncodingUtils(com.palantir.atlasdb.ptobject.EncodingUtils) PreCommitCondition(com.palantir.atlasdb.transaction.api.PreCommitCondition) Matchers(org.hamcrest.Matchers) TimestampCache(com.palantir.atlasdb.cache.TimestampCache) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Ignore(org.junit.Ignore) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) TransactionFailedNonRetriableException(com.palantir.atlasdb.transaction.api.TransactionFailedNonRetriableException) NameMetadataDescription(com.palantir.atlasdb.table.description.NameMetadataDescription) Collections(java.util.Collections) AbortingVisitor(com.palantir.common.base.AbortingVisitor) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) AbortingVisitor(com.palantir.common.base.AbortingVisitor) TransactionLockTimeoutNonRetriableException(com.palantir.atlasdb.transaction.api.TransactionLockTimeoutNonRetriableException) TransactionFailedRetriableException(com.palantir.atlasdb.transaction.api.TransactionFailedRetriableException) ExecutionException(java.util.concurrent.ExecutionException) TransactionConflictException(com.palantir.atlasdb.transaction.api.TransactionConflictException) TransactionFailedNonRetriableException(com.palantir.atlasdb.transaction.api.TransactionFailedNonRetriableException) BatchingVisitable(com.palantir.common.base.BatchingVisitable) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Random(java.util.Random) Transaction(com.palantir.atlasdb.transaction.api.Transaction) MutableInt(org.apache.commons.lang3.mutable.MutableInt) BigInteger(java.math.BigInteger) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Aggregations

Assert.assertEquals (org.junit.Assert.assertEquals)68 Assert (org.junit.Assert)67 Test (org.junit.Test)62 List (java.util.List)56 Before (org.junit.Before)42 Assert.assertTrue (org.junit.Assert.assertTrue)41 ArrayList (java.util.ArrayList)39 Assert.assertFalse (org.junit.Assert.assertFalse)39 Arrays (java.util.Arrays)29 Assert.assertNotNull (org.junit.Assert.assertNotNull)29 Collections (java.util.Collections)28 Map (java.util.Map)25 After (org.junit.After)25 HashMap (java.util.HashMap)24 Collectors (java.util.stream.Collectors)24 Assert.assertNull (org.junit.Assert.assertNull)23 Set (java.util.Set)17 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)15 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)15 SysSystemService (eu.bcvsolutions.idm.acc.service.api.SysSystemService)15