use of org.infinispan.test.fwk.InCacheMode in project infinispan by infinispan.
the class PutForExternalReadTest method testKeyOnlyWrittenOnceOnOriginator.
// This test executes PFER on cache1, and expects that it will be relayed to cache2 == primary
// and then sent to cache1 again for backup. In scattered cache there's only one RPC.
@InCacheMode({ CacheMode.DIST_SYNC, CacheMode.REPL_SYNC })
public void testKeyOnlyWrittenOnceOnOriginator() throws Exception {
final Cache<MagicKey, String> cache1 = cache(0, CACHE_NAME);
final Cache<MagicKey, String> cache2 = cache(1, CACHE_NAME);
final CyclicBarrier barrier = new CyclicBarrier(2);
cache1.getAdvancedCache().getAsyncInterceptorChain().addInterceptor(new BaseAsyncInterceptor() {
@Override
public Object visitCommand(InvocationContext ctx, VisitableCommand command) throws Throwable {
if (command instanceof PutKeyValueCommand) {
if (!ctx.isOriginLocal()) {
// wait first before the check
TestBlocking.await(barrier, 10, TimeUnit.SECONDS);
// and once more after the check
TestBlocking.await(barrier, 10, TimeUnit.SECONDS);
}
}
return invokeNext(ctx, command);
}
}, 0);
final MagicKey myKey = new MagicKey(cache2);
cache1.putForExternalRead(myKey, value);
// Verify that the key was not written on the origin by the time it was looped back
barrier.await(10, TimeUnit.SECONDS);
assertNull(cache1.get(myKey));
// Verify that the key is written on the origin afterwards
barrier.await(10, TimeUnit.SECONDS);
eventually(() -> value.equals(cache1.get(myKey)) && value.equals(cache2.get(myKey)));
}
use of org.infinispan.test.fwk.InCacheMode in project infinispan by infinispan.
the class MultipleCacheManagersTest method defaultFactory.
@Factory
public Object[] defaultFactory() {
try {
// Ignore any inherited factory() method and only run methods defined in the current class
Method factory = getClass().getMethod("factory");
if (factory.getDeclaringClass() == getClass()) {
if (getClass().getAnnotation(InCacheMode.class) != null || getClass().getAnnotation(InTransactionMode.class) != null) {
return new Object[] { new TestFrameworkFailure<>(getClass(), new IllegalStateException("Tests with factory() methods ignore @InCacheMode and @InTransactionMode annotations, " + "please remove them.")) };
}
Object[] instances = factory();
for (int i = 0; i < instances.length; i++) {
if (instances[i].getClass() != getClass()) {
instances[i] = new TestFrameworkFailure<>(getClass(), "%s.factory() creates instances of %s", getClass().getName(), instances[i].getClass().getName());
}
}
return instances;
}
} catch (NoSuchMethodException e) {
throw new IllegalStateException("Every class should have factory method, at least inherited", e);
}
List<Consumer<MultipleCacheManagersTest>[]> allModifiers;
try {
Consumer<MultipleCacheManagersTest>[] cacheModeModifiers = getModifiers(InCacheMode.class, InCacheMode::value, MultipleCacheManagersTest::cacheMode);
Consumer<MultipleCacheManagersTest>[] transactionModifiers = getModifiers(InTransactionMode.class, InTransactionMode::value, (t, m) -> t.transactional(m.isTransactional()));
allModifiers = asList(cacheModeModifiers, transactionModifiers);
} catch (Exception e) {
return new Object[] { new TestFrameworkFailure<>(getClass(), e) };
}
int numTests = allModifiers.stream().mapToInt(m -> m.length).reduce(1, (m1, m2) -> m1 * m2);
Object[] tests = new Object[numTests];
tests[0] = this;
Constructor<? extends MultipleCacheManagersTest> ctor;
try {
ctor = getClass().getConstructor();
} catch (NoSuchMethodException e) {
return new Object[] { new TestFrameworkFailure<>(getClass(), "Missing no-arg constructor in %s", getClass().getName()) };
}
for (int i = 1; i < tests.length; ++i) {
try {
tests[i] = ctor.newInstance();
} catch (Exception e) {
return new Object[] { new TestFrameworkFailure<>(getClass(), e) };
}
}
int stride = 1;
for (Consumer<MultipleCacheManagersTest>[] modifiers : allModifiers) {
applyModifiers(tests, modifiers, stride);
stride *= modifiers.length;
}
return tests;
}
Aggregations