Search in sources :

Example 1 with Resource

use of org.neo4j.graphdb.Resource in project neo4j by neo4j.

the class StoreCopyCheckPointMutexTest method checkPointShouldBlockStoreCopy.

@Test
public void checkPointShouldBlockStoreCopy() throws Exception {
    // GIVEN
    try (Resource lock = mutex.checkPoint()) {
        // WHEN
        t2.execute(state -> mutex.storeCopy(NO_OP));
        // THEN
        t2.get().waitUntilWaiting(details -> details.isAt(StoreCopyCheckPointMutex.class, "storeCopy"));
    }
}
Also used : Resource(org.neo4j.graphdb.Resource) Test(org.junit.Test)

Example 2 with Resource

use of org.neo4j.graphdb.Resource in project neo4j by neo4j.

the class StoreCopyCheckPointMutexTest method checkPointShouldBlockAnotherCheckPoint.

@Test
public void checkPointShouldBlockAnotherCheckPoint() throws Exception {
    // GIVEN
    try (Resource lock = mutex.checkPoint()) {
        // WHEN
        t2.execute(state -> mutex.checkPoint());
        // THEN
        t2.get().waitUntilWaiting(details -> details.isAt(StoreCopyCheckPointMutex.class, "checkPoint"));
    }
}
Also used : Resource(org.neo4j.graphdb.Resource) Test(org.junit.Test)

Example 3 with Resource

use of org.neo4j.graphdb.Resource in project neo4j by neo4j.

the class StoreCopyCheckPointMutexTest method shouldHandleMultipleConcurrentStoreCopyWhenBeforeActionPerformsCheckPoint.

@Test
public void shouldHandleMultipleConcurrentStoreCopyWhenBeforeActionPerformsCheckPoint() throws Throwable {
    // GIVEN a check-point action which asserts calls to it along the way
    CheckPointingAction checkPointingAction = new CheckPointingAction(mutex);
    for (int i = 0; i < 2; i++) {
        // Start first store-copy and assert that the check-point action is triggered
        Resource firstLock = mutex.storeCopy(checkPointingAction);
        assertNotNull(checkPointingAction.lock);
        // A second store-copy starts while the first is still going
        Resource secondLock = mutex.storeCopy(checkPointingAction);
        // The first store-copy completes
        firstLock.close();
        // A third store-copy starts and completes
        Resource thirdLock = mutex.storeCopy(checkPointingAction);
        thirdLock.close();
        // Second store-copy completes
        secondLock.close();
        checkPointingAction.unlock();
    // Go another round, now that the check-point action has been reset.
    // Next round will assert that the mutex got the counting of store-copy jobs right
    }
}
Also used : Resource(org.neo4j.graphdb.Resource) Test(org.junit.Test)

Example 4 with Resource

use of org.neo4j.graphdb.Resource in project neo4j by neo4j.

the class StoreCopyCheckPointMutexTest method storeCopyShouldBlockCheckPoint.

@Test
public void storeCopyShouldBlockCheckPoint() throws Exception {
    // GIVEN
    try (Resource lock = mutex.storeCopy(NO_OP)) {
        // WHEN
        t2.execute(state -> mutex.checkPoint());
        // THEN
        t2.get().waitUntilWaiting(details -> details.isAt(StoreCopyCheckPointMutex.class, "checkPoint"));
    }
}
Also used : Resource(org.neo4j.graphdb.Resource) Test(org.junit.Test)

Example 5 with Resource

use of org.neo4j.graphdb.Resource in project neo4j by neo4j.

the class TestCommonIterators method iterablesStreamClosesResourceIterator.

@Test
public void iterablesStreamClosesResourceIterator() {
    List<Object> list = Arrays.asList("a", "b", "c", "def");
    Resource resource = mock(Resource.class);
    ResourceIterable<Object> iterable = () -> Iterators.resourceIterator(list.iterator(), resource);
    try (Stream<Object> stream = Iterables.stream(iterable)) {
        assertEquals(list, stream.collect(toList()));
    }
    verify(resource).close();
}
Also used : Resource(org.neo4j.graphdb.Resource) Test(org.junit.Test)

Aggregations

Resource (org.neo4j.graphdb.Resource)12 Test (org.junit.Test)8 StoreFileMetadata (org.neo4j.storageengine.api.StoreFileMetadata)3 File (java.io.File)2 IOException (java.io.IOException)2 PagedFile (org.neo4j.io.pagecache.PagedFile)2 SimpleTriggerInfo (org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo)2 Race (org.neo4j.test.Race)2 ByteBuffer (java.nio.ByteBuffer)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 LockSupport (java.util.concurrent.locks.LockSupport)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.lessThan (org.hamcrest.Matchers.lessThan)1