protected void killSpawnedThreads() { List<Runnable> runnables = defaultExecutorService.shutdownNow(); if (!runnables.isEmpty()) { log.errorf("There were runnables %s left uncompleted in test %s", runnables, getClass().getSimpleName()); } }
@AfterMethod protected void checkThreads() { int activeTasks = defaultExecutorService.getActiveCount(); if (activeTasks != 0) { log.errorf("There were %d active tasks found in the test executor service for class %s", activeTasks, getClass().getSimpleName()); } }
@Override public Boolean call() throws Exception { boolean success; try { doRun(); success = true; } catch (Throwable t) { log.errorf(t, "Error in Worker[%s, unlock? %s]", index, withUnlock); success = false; } return success; }
@Override public void onUpdate(CounterEvent event) { try { queue.put(event); if (trace) { log.tracef("[%s] add event %s", name, event); } } catch (InterruptedException e) { log.errorf(e, "[%s] interrupted while adding event %s", name, event); } }
void fail(Throwable e) { if (latch.isCompletedExceptionally()) { latch.join(); } log.errorf(e, "Failed waiting for test to unblock %s %d on %s", type, topologyId, address); failManager(e); latch.completeExceptionally(e); }
@Override public void run() { try { // should be much larger than the lock acquisition timeout Thread.sleep(1000); manager(c2).stop(); // stLock.unblockNewTransactions(1000); } catch (InterruptedException e) { log.errorf(e, "Error stopping cache"); } } };
@Test(dependsOnMethods = "sequantialOvewritingInBatches") public void indexWasStored() { cache = cacheManager.getCache(); Assert.assertEquals(0, cache.getAdvancedCache().getDataContainer().size()); boolean failed = false; for (Object key : cacheCopy.keySet()) { Object expected = cacheCopy.get(key); Object actual = cache.get(key); if (!expected.equals(actual)) { log.errorf("Failure on key '%s' expected value: '%s' actual value: '%s'", key.toString(), expected, actual); failed = true; } } Assert.assertFalse(failed); Assert.assertEquals(cacheCopy.keySet().size(), cache.keySet().size(), "have a different number of keys"); }
@Override public Integer call() throws Exception { int c = 0; while (!stop) { boolean success = false; try { if (tx) tm.begin(); cache.put("test" + c, c); if (tx) tm.commit(); success = true; c++; // Without this, the writing thread would occupy 1 core completely before the 2nd node joins. Thread.sleep(1); } catch (Exception e) { log.errorf(e, "Error writing key test%s", c); stop(); } finally { if (tx && !success) { try { tm.rollback(); } catch (SystemException e) { log.error(e); } } } } return c; }
log.errorf(" >> Saw a %s when trying to process key %s", exception.getClass().getSimpleName(), key); } else { throw new RuntimeException(exception);
protected Future<Void> beginAndCommitTx(final Object k, final int cacheIndex) { return fork(() -> { try { tm(cacheIndex).begin(); cache(cacheIndex).put(k, "v"); tm(cacheIndex).commit(); } catch (Throwable e) { log.errorf(e, "Error committing transaction for key %s on cache %s", k, cache(cacheIndex)); } }); }
protected Future<Void> beginAndPrepareTx(final Object k, final int cacheIndex) { return fork(() -> { try { tm(cacheIndex).begin(); cache(cacheIndex).put(k,"v"); final EmbeddedTransaction transaction = (EmbeddedTransaction) tm(cacheIndex).getTransaction(); transaction.runPrepare(); } catch (Throwable e) { log.errorf(e, "Error preparing transaction for key %s on cache %s", k, cache(cacheIndex)); } }); }
@Override public void run() { try { // Before calling commit we block transactions on one of the nodes to simulate a state transfer final StateTransferLock blockFirst = TestingUtil.extractComponent(failOnOriginator ? c1 : c2, StateTransferLock.class); final StateTransferLock blockSecond = TestingUtil.extractComponent(failOnOriginator ? c2 : c1, StateTransferLock.class); try { blockFirst.acquireExclusiveTopologyLock(); blockSecond.acquireExclusiveTopologyLock(); commitLatch.countDown(); // should be much larger than the lock acquisition timeout Thread.sleep(1000); } finally { blockSecond.releaseExclusiveTopologyLock(); blockFirst.releaseExclusiveTopologyLock(); } } catch (Throwable t) { log.errorf(t, "Error blocking/unblocking transactions"); } } };
@Override protected void afterConflictResolutionAndMerge() { ConflictManager cm = conflictManager(0); assertFalse(cm.isConflictResolutionInProgress()); for (String key : ALL_KEYS) { Map<Address, InternalCacheValue> versionMap = cm.getAllVersions(key); assertNotNull(versionMap); assertEquals("Versions: " + versionMap, numberOfOwners, versionMap.size()); String message = String.format("Key=%s. VersionMap: %s", key, versionMap); for (InternalCacheValue icv : versionMap.values()) { assertNotNull(message, icv); assertNotNull(message, icv.getValue()); assertEquals(message, valueAfterMerge, icv.getValue()); } } assertEquals(0, cm.getConflicts().peek(m -> log.errorf("Conflict: " + m)).count()); }
public static void clearContent(EmbeddedCacheManager cacheContainer) { if (cacheContainer != null && cacheContainer.getStatus().allowInvocations()) { Set<Cache> runningCaches = getRunningCaches(cacheContainer); for (Cache cache : runningCaches) { clearRunningTx(cache); } if (!cacheContainer.getStatus().allowInvocations()) return; for (Cache cache : runningCaches) { try { clearCacheLoader(cache); removeInMemoryData(cache); } catch (Exception e) { log.errorf(e, "Failed to clear cache %s after test", cache); } } } }
transaction.runPrepare(); } catch (Throwable e) { log.errorf(e, "Error preparing transaction for key %s", k);
public void testLockOwnerCrashesBeforePrepare() throws Exception { final Object k = getKeyForCache(2); inNewThread(() -> { try { tm(1).begin(); cache(1).put(k, "v"); transaction = (EmbeddedTransaction) tm(1).getTransaction(); } catch (Throwable e) { log.errorf(e, "Error starting transaction for key %s", k); } }); eventually(() -> checkTxCount(0, 0, 0) && checkTxCount(1, 1, 0)&& checkTxCount(2, 0, 0)); killMember(2); assert caches().size() == 2; tm(1).resume(transaction); tm(1).commit(); assertEquals("v", cache(0).get(k)); assertEquals("v", cache(1).get(k)); assertNotLocked(k); eventually(() -> checkTxCount(0, 0, 0) && checkTxCount(1, 0, 0)); }
public void testLockOwnerCrashesBeforePrepareAndLockIsStillHeld() throws Exception { final Object k = getKeyForCache(2); inNewThread(() -> { try { tm(1).begin(); cache(1).put(k, "v"); transaction = (EmbeddedTransaction) tm(1).getTransaction(); } catch (Throwable e) { log.errorf(e, "Error starting transaction for key %s", k); } }); eventually(() -> !checkLocked(0, k) && !checkLocked(1, k) && checkLocked(2, k)); killMember(2); assert caches().size() == 2; tm(0).begin(); try { cache(0).put(k, "v1"); assert false; } catch (Exception e) { tm(0).rollback(); } tm(1).resume(transaction); tm(1).commit(); assertEquals("v", cache(0).get(k)); assertEquals("v", cache(1).get(k)); assertNotLocked(k); eventually(() -> checkTxCount(0, 0, 0) && checkTxCount(1, 0, 0)); }
public void testLockOwnerCrashesBeforePrepare() throws Exception { final Object k = getKeyForCache(2); inNewThread(() -> { try { tm(1).begin(); cache(1).put(k, "v"); transaction = (EmbeddedTransaction) tm(1).getTransaction(); } catch (Throwable e) { log.errorf(e, "Error starting transaction for key %s", k); } }); eventually(() -> checkTxCount(0, 0, 1) && checkTxCount(1, 1, 0) && checkTxCount(2, 0, 1)); eventually(() -> !checkLocked(0, k) && !checkLocked(1, k) && checkLocked(2, k)); killMember(2); assert caches().size() == 2; tm(1).resume(transaction); tm(1).commit(); assertEquals("v", cache(0).get(k)); assertEquals("v", cache(1).get(k)); assertNotLocked(k); eventually(() -> checkTxCount(0, 0, 0) && checkTxCount(1, 0, 0)); }
log.errorf(t, "Error killing cache %s", c.getName());