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"));
}
}
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"));
}
}
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
}
}
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"));
}
}
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();
}
Aggregations