use of org.apache.jackrabbit.oak.segment.SegmentNodeStoreStats in project jackrabbit-oak by apache.
the class LockBasedSchedulerTest method testSimulatedRaceOnRevisions.
/**
* OAK-7162
*
* This test guards against race conditions which may happen when the head
* state in {@link Revisions} is changed from outside the scheduler. If a
* race condition happens at that point, data from a single commit will be
* lost.
*/
@Test
public void testSimulatedRaceOnRevisions() throws Exception {
final MemoryStore ms = new MemoryStore();
StatisticsProvider statsProvider = StatisticsProvider.NOOP;
SegmentNodeStoreStats stats = new SegmentNodeStoreStats(statsProvider);
final LockBasedScheduler scheduler = LockBasedScheduler.builder(ms.getRevisions(), ms.getReader(), stats).build();
final RecordId initialHead = ms.getRevisions().getHead();
ExecutorService executorService = newFixedThreadPool(10);
final AtomicInteger count = new AtomicInteger();
final Random rand = new Random();
try {
Callable<PropertyState> commitTask = new Callable<PropertyState>() {
@Override
public PropertyState call() throws Exception {
String property = "prop" + count.incrementAndGet();
Commit commit = createCommit(scheduler, property, "value");
SegmentNodeState result = (SegmentNodeState) scheduler.schedule(commit);
return result.getProperty(property);
}
};
Callable<Void> parallelTask = new Callable<Void>() {
@Override
public Void call() throws Exception {
Thread.sleep(rand.nextInt(10));
ms.getRevisions().setHead(ms.getRevisions().getHead(), initialHead);
return null;
}
};
List<Future<?>> results = newArrayList();
for (int i = 0; i < 100; i++) {
results.add(executorService.submit(commitTask));
executorService.submit(parallelTask);
}
for (Future<?> result : results) {
assertNotNull("PropertyState must not be null! The corresponding commit got lost because of a race condition.", result.get());
}
} finally {
new ExecutorCloser(executorService).close();
}
}
use of org.apache.jackrabbit.oak.segment.SegmentNodeStoreStats in project jackrabbit-oak by apache.
the class LockBasedSchedulerCheckpointTest method testShortWait.
/**
* OAK-3587 test simulates a timeout while trying to create a checkpoint,
* then releases the lock and tries again
*/
@Test
public void testShortWait() throws Exception {
MemoryStore ms = new MemoryStore();
System.setProperty("oak.checkpoints.lockWaitTime", "1");
StatisticsProvider statsProvider = StatisticsProvider.NOOP;
SegmentNodeStoreStats stats = new SegmentNodeStoreStats(statsProvider);
final LockBasedScheduler scheduler = LockBasedScheduler.builder(ms.getRevisions(), ms.getReader(), stats).build();
final Semaphore semaphore = new Semaphore(0);
final AtomicBoolean blocking = new AtomicBoolean(true);
final Callable<Boolean> block = new Callable<Boolean>() {
@Override
public Boolean call() {
while (blocking.get()) {
if (semaphore.availablePermits() == 0) {
semaphore.release();
}
}
return true;
}
};
Thread background = new Thread() {
@Override
public void run() {
try {
Commit commit = createBlockingCommit(scheduler, "foo", "bar", block);
scheduler.schedule(commit);
} catch (Exception e) {
//
}
}
};
background.start();
semaphore.acquire();
String cp0 = scheduler.checkpoint(10, Collections.<String, String>emptyMap());
assertNull(retrieveCheckpoint(scheduler, cp0));
blocking.set(false);
String cp1 = scheduler.checkpoint(10, Collections.<String, String>emptyMap());
assertNotNull(retrieveCheckpoint(scheduler, cp1));
}
use of org.apache.jackrabbit.oak.segment.SegmentNodeStoreStats in project jackrabbit-oak by apache.
the class LockBasedSchedulerCheckpointTest method testLongWait.
/**
* OAK-3587 test simulates a wait less than configured
* {@code SegmentNodeStore#setCheckpointsLockWaitTime(int)} value so the
* checkpoint call must return a valid value
*/
@Test
public void testLongWait() throws Exception {
final int blockTime = 1;
MemoryStore ms = new MemoryStore();
System.setProperty("oak.checkpoints.lockWaitTime", "2");
StatisticsProvider statsProvider = StatisticsProvider.NOOP;
SegmentNodeStoreStats stats = new SegmentNodeStoreStats(statsProvider);
final LockBasedScheduler scheduler = LockBasedScheduler.builder(ms.getRevisions(), ms.getReader(), stats).build();
final Semaphore semaphore = new Semaphore(0);
final Callable<Boolean> block = new Callable<Boolean>() {
@Override
public Boolean call() {
try {
semaphore.release();
SECONDS.sleep(blockTime);
} catch (InterruptedException e) {
//
}
return true;
}
};
Thread background = new Thread() {
@Override
public void run() {
try {
Commit commit = createBlockingCommit(scheduler, "foo", "bar", block);
scheduler.schedule(commit);
} catch (Exception e) {
//
}
}
};
background.start();
semaphore.acquire();
String cp0 = scheduler.checkpoint(10, Collections.<String, String>emptyMap());
assertNotNull(retrieveCheckpoint(scheduler, cp0));
}
Aggregations