private void runAssertion(CacheOperation operation) throws NotSupportedException, SystemException, HeuristicMixedException, HeuristicRollbackException, InvalidTransactionException, RollbackException { txStatus.reset(); tm.begin(); cache(1).put("k1", "v1"); Transaction k1LockOwner = tm.suspend(); assert lm1.isLocked("k1"); assertEquals(1, txTable1.getLocalTxCount()); tm.begin(); cache(0).put("k2", "v2"); assert lm0.isLocked("k2"); assert !lm1.isLocked("k2"); operation.execute(); assertEquals(1, txTable1.getLocalTxCount()); assertEquals(1, txTable0.getLocalTxCount()); try { tm.commit(); assert false; } catch (RollbackException re) { // expected } assert txStatus.teReceived; assert txStatus.isTxInTableAfterTeOnPrepare; // expect 1 as k1 is locked by the other tx assertEquals( txStatus.numLocksAfterTeOnPrepare, 1, "This would make sure that locks are being released quickly, not waiting for a remote rollback to happen"); assertEquals(0, txTable0.getLocalTxCount()); assertEquals(1, txTable1.getLocalTxCount()); log.trace("Right before second commit"); tm.resume(k1LockOwner); tm.commit(); assertEquals("v1", cache(0).get("k1")); assertEquals("v1", cache(1).get("k1")); assertEquals(0, txTable1.getLocalTxCount()); assertEquals(0, txTable1.getLocalTxCount()); assertEquals(0, lm0.getNumberOfLocksHeld()); assertEquals(0, lm1.getNumberOfLocksHeld()); }
@Override public Map<String, Number> call() throws Exception { Map<String, Number> map = new HashMap<>(); Stats stats = remoteCache.getStats(); map.put(AVERAGE_READ_TIME, stats.getAverageReadTime()); map.put(AVERAGE_WRITE_TIME, stats.getAverageWriteTime()); map.put(AVERAGE_REMOVE_TIME, stats.getAverageRemoveTime()); map.put(EVICTIONS, stats.getEvictions()); map.put(HITS, stats.getHits()); map.put(MISSES, stats.getMisses()); final CacheMode cacheMode = getCacheMode(remoteCache); // for replicated caches, we don't need to send the number of entries since it is the same in // all the nodes. if (cacheMode.isDistributed()) { map.put(NUMBER_OF_ENTRIES, stats.getCurrentNumberOfEntries() / numOwners()); } else if (!cacheMode.isReplicated()) { map.put(NUMBER_OF_ENTRIES, stats.getCurrentNumberOfEntries()); } map.put(STORES, stats.getStores()); map.put(REMOVE_HITS, stats.getRemoveHits()); map.put(REMOVE_MISSES, stats.getRemoveMisses()); map.put(TIME_SINCE_START, stats.getTimeSinceStart()); LockManager lockManager = remoteCache.getLockManager(); map.put(NUMBER_OF_LOCKS_HELD, lockManager.getNumberOfLocksHeld()); // number of locks available is not exposed through the LockManager interface map.put(NUMBER_OF_LOCKS_AVAILABLE, 0); // invalidations InvalidationInterceptor invalidationInterceptor = getFirstInterceptorWhichExtends(remoteCache, InvalidationInterceptor.class); if (invalidationInterceptor != null) { map.put(INVALIDATIONS, invalidationInterceptor.getInvalidations()); } else { map.put(INVALIDATIONS, 0); } // passivations PassivationManager pManager = remoteCache.getComponentRegistry().getComponent(PassivationManager.class); if (pManager != null) { map.put(PASSIVATIONS, pManager.getPassivations()); } else { map.put(PASSIVATIONS, 0); } // activations ActivationManager aManager = remoteCache.getComponentRegistry().getComponent(ActivationManager.class); if (pManager != null) { map.put(ACTIVATIONS, aManager.getActivationCount()); } else { map.put(ACTIVATIONS, 0); } // cache loaders ActivationInterceptor aInterceptor = getFirstInterceptorWhichExtends(remoteCache, ActivationInterceptor.class); if (aInterceptor != null) { map.put(CACHE_LOADER_LOADS, aInterceptor.getCacheLoaderLoads()); map.put(CACHE_LOADER_MISSES, aInterceptor.getCacheLoaderMisses()); } else { map.put(CACHE_LOADER_LOADS, 0); map.put(CACHE_LOADER_MISSES, 0); } // cache store CacheWriterInterceptor interceptor = getFirstInterceptorWhichExtends(remoteCache, CacheWriterInterceptor.class); if (interceptor != null) { map.put(CACHE_WRITER_STORES, interceptor.getWritesToTheStores()); } else { map.put(CACHE_WRITER_STORES, 0); } return map; }