Search in sources :

Example 1 with RepeatedIfExceptionsTest

use of io.github.artsok.RepeatedIfExceptionsTest in project netty by netty.

the class EpollSocketChannelConfigTest method testSetOptionWhenClosed.

// For this test to pass, we are relying on the sockets file descriptor not being reused after the socket is closed.
// This is inherently racy, so we allow getSoLinger to throw ChannelException a few of times, but eventually we do
// want to see a ClosedChannelException for the test to pass.
@RepeatedIfExceptionsTest(repeats = 4)
public void testSetOptionWhenClosed() {
    ch.close().syncUninterruptibly();
    ChannelException e = assertThrows(ChannelException.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            ch.config().setSoLinger(0);
        }
    });
    assertThat(e).hasCauseInstanceOf(ClosedChannelException.class);
}
Also used : Executable(org.junit.jupiter.api.function.Executable) ClosedChannelException(java.nio.channels.ClosedChannelException) ChannelException(io.netty.channel.ChannelException) RepeatedIfExceptionsTest(io.github.artsok.RepeatedIfExceptionsTest)

Example 2 with RepeatedIfExceptionsTest

use of io.github.artsok.RepeatedIfExceptionsTest in project janusgraph by JanusGraph.

the class JanusGraphIndexTest method shouldUpdateIndexFieldsAfterIndexModification.

@RepeatedIfExceptionsTest(repeats = 4, minSuccess = 2)
public void shouldUpdateIndexFieldsAfterIndexModification() throws InterruptedException, ExecutionException {
    clopen(option(FORCE_INDEX_USAGE), true, option(LOG_READ_INTERVAL, MANAGEMENT_LOG), Duration.ofMillis(5000));
    String key1 = "testKey1";
    String key2 = "testKey2";
    String key3 = "testKey3";
    String vertexL = "testVertexLabel";
    String indexName = "mixed";
    PropertyKey p1 = mgmt.makePropertyKey(key1).dataType(Long.class).make();
    PropertyKey p2 = mgmt.makePropertyKey(key2).dataType(Long.class).make();
    mgmt.makeVertexLabel(vertexL).make();
    JanusGraphIndex index = mgmt.buildIndex(indexName, Vertex.class).indexOnly(mgmt.getVertexLabel(vertexL)).addKey(mgmt.getPropertyKey(key1)).addKey(mgmt.getPropertyKey(key2)).buildMixedIndex(INDEX);
    if (index.getIndexStatus(p1) == SchemaStatus.INSTALLED) {
        mgmt.updateIndex(mgmt.getGraphIndex(indexName), SchemaAction.REGISTER_INDEX).get();
        mgmt.updateIndex(mgmt.getGraphIndex(indexName), SchemaAction.ENABLE_INDEX).get();
    } else if (index.getIndexStatus(p1) == SchemaStatus.REGISTERED) {
        mgmt.updateIndex(mgmt.getGraphIndex(indexName), SchemaAction.ENABLE_INDEX).get();
    }
    mgmt.commit();
    JanusGraphVertex vertex = graph.addVertex(vertexL);
    vertex.property(key1, 111L);
    vertex.property(key2, 222L);
    graph.tx().commit();
    // By default ES indexes documents each second. By sleeping here we guarantee that documents are indexed.
    // It is just for testing. A better approach is to use Refresh API.
    Thread.sleep(1500L);
    // we open an implicit transaction and do not commit/rollback it by intention, so that we can ensure
    // adding new property to the index wouldn't cause existing transactions to fail
    assertEquals(1, graph.traversal().V().hasLabel(vertexL).has(key1, 111L).count().next());
    assertEquals(1, graph.traversal().V().hasLabel(vertexL).has(key1, 111L).toList().size());
    JanusGraph graph2 = JanusGraphFactory.open(config);
    assertEquals(1, graph2.traversal().V().hasLabel(vertexL).has(key1, 111L).count().next());
    assertEquals(1, graph2.traversal().V().hasLabel(vertexL).has(key1, 111L).toList().size());
    mgmt = graph.openManagement();
    PropertyKey testKey3 = mgmt.makePropertyKey(key3).dataType(Long.class).make();
    mgmt.addIndexKey(mgmt.getGraphIndex(indexName), testKey3);
    mgmt.commit();
    ManagementSystem.awaitGraphIndexStatus(graph, indexName).status(SchemaStatus.REGISTERED, SchemaStatus.ENABLED).call();
    mgmt = graph.openManagement();
    mgmt.updateIndex(mgmt.getGraphIndex(indexName), SchemaAction.REINDEX).get();
    mgmt.commit();
    graph.addVertex(T.label, vertexL, key1, 1L, key2, 2L, key3, 3L);
    graph.tx().commit();
    assertTrue(graph.traversal().V().hasLabel(vertexL).has(key3, 3L).hasNext());
    try {
        graph2.addVertex(T.label, vertexL, key1, 1L, key2, 2L, key3, 3L);
        // this assertion might be flaky which is why we mark this test as RepeatedIfExceptionsTest.
        // the reason is, we cannot make sure when the schema update broadcast will be received by the graph2
        // instance.
        JanusGraphException ex = assertThrows(JanusGraphException.class, () -> graph2.tx().commit());
        assertEquals("testKey3 is not available in mixed index mixed", ex.getCause().getMessage());
        // graph2 needs some time to read from ManagementLogger asynchronously and updates cache
        // LOG_READ_INTERVAL is 5 seconds, so we wait for the same time here to ensure periodic read is triggered
        Thread.sleep(5000);
        graph2.tx().commit();
        assertTrue(graph2.traversal().V().hasLabel(vertexL).has(key3, 3L).hasNext());
    } finally {
        graph2.close();
    }
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) JanusGraph(org.janusgraph.core.JanusGraph) JanusGraphException(org.janusgraph.core.JanusGraphException) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) RepeatedIfExceptionsTest(io.github.artsok.RepeatedIfExceptionsTest)

Example 3 with RepeatedIfExceptionsTest

use of io.github.artsok.RepeatedIfExceptionsTest in project janusgraph by JanusGraph.

the class StandardVertexTest method shouldNotStuckInDeadlockWhenTheVerticeAndItsRelationIsDeletedInParallel.

@RepeatedIfExceptionsTest(repeats = 3, minSuccess = 1)
public void shouldNotStuckInDeadlockWhenTheVerticeAndItsRelationIsDeletedInParallel() throws InterruptedException, TimeoutException, ExecutionException {
    ExecutorService es = Executors.newSingleThreadExecutor();
    Future<?> future = es.submit(() -> {
        when(internalRelation.isLoaded()).thenReturn(true);
        ReentrantLock lock = new ReentrantLock();
        Condition vertexRemoveCondition = lock.newCondition();
        Condition relationRemoveCondition = lock.newCondition();
        AtomicBoolean removeVertexCalled = new AtomicBoolean(false);
        AtomicBoolean removeRelationExecuted = new AtomicBoolean(false);
        doAnswer(invocation -> {
            lock.lock();
            try {
                removeVertexCalled.set(true);
                vertexRemoveCondition.signalAll();
                while (!removeRelationExecuted.get()) {
                    relationRemoveCondition.await();
                }
                standardVertex.updateLifeCycle(ElementLifeCycle.Event.REMOVED);
            } finally {
                lock.unlock();
            }
            return null;
        }).when(standardVertex).remove();
        new Thread(() -> standardVertex.remove()).start();
        lock.lock();
        try {
            while (!removeVertexCalled.get()) {
                vertexRemoveCondition.await();
            }
            standardVertex.removeRelation(internalRelation);
            removeRelationExecuted.set(true);
            relationRemoveCondition.signalAll();
        } finally {
            lock.unlock();
        }
        return null;
    });
    future.get(defaultTimeoutMilliseconds, TimeUnit.MILLISECONDS);
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Condition(java.util.concurrent.locks.Condition) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExecutorService(java.util.concurrent.ExecutorService) RepeatedIfExceptionsTest(io.github.artsok.RepeatedIfExceptionsTest)

Example 4 with RepeatedIfExceptionsTest

use of io.github.artsok.RepeatedIfExceptionsTest in project netty by netty.

the class EpollSocketChannelConfigTest method testGetOptionWhenClosed.

// For this test to pass, we are relying on the sockets file descriptor not being reused after the socket is closed.
// This is inherently racy, so we allow getSoLinger to throw ChannelException a few of times, but eventually we do
// want to see a ClosedChannelException for the test to pass.
@RepeatedIfExceptionsTest(repeats = 4)
public void testGetOptionWhenClosed() {
    ch.close().syncUninterruptibly();
    ChannelException e = assertThrows(ChannelException.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            ch.config().getSoLinger();
        }
    });
    assertThat(e).hasCauseInstanceOf(ClosedChannelException.class);
}
Also used : Executable(org.junit.jupiter.api.function.Executable) ClosedChannelException(java.nio.channels.ClosedChannelException) ChannelException(io.netty.channel.ChannelException) RepeatedIfExceptionsTest(io.github.artsok.RepeatedIfExceptionsTest)

Aggregations

RepeatedIfExceptionsTest (io.github.artsok.RepeatedIfExceptionsTest)4 ChannelException (io.netty.channel.ChannelException)2 ClosedChannelException (java.nio.channels.ClosedChannelException)2 Executable (org.junit.jupiter.api.function.Executable)2 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Condition (java.util.concurrent.locks.Condition)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 JanusGraph (org.janusgraph.core.JanusGraph)1 JanusGraphException (org.janusgraph.core.JanusGraphException)1 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)1 PropertyKey (org.janusgraph.core.PropertyKey)1 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)1