public static Object prepare(
     TxInvocationContext txInvocationContext,
     PrepareCommand prepareCommand,
     TotalOrderRpcInterceptor interceptor)
     throws Throwable {
   if (log.isTraceEnabled()) {
     log.tracef("Preparing transaction %s", prepareCommand.getGlobalTransaction().prettyPrint());
   }
   try {
     Object result = interceptor.visitPrepare(txInvocationContext, prepareCommand);
     if (log.isTraceEnabled()) {
       log.tracef(
           "Successful prepare of transaction %s",
           prepareCommand.getGlobalTransaction().prettyPrint());
     }
     return result;
   } catch (CacheException cacheException) {
     Throwable cause = cacheException.getCause();
     if (cause instanceof StateTransferException) {
       if (log.isTraceEnabled()) {
         log.tracef(
             "Transaction %s should be re-prepare",
             prepareCommand.getGlobalTransaction().prettyPrint());
       }
       throw (StateTransferException) cause;
     } else {
       if (log.isTraceEnabled()) {
         log.tracef(
             "Error preparing transaction %s: %s",
             prepareCommand.getGlobalTransaction().prettyPrint(), cacheException.getCause());
       }
       throw cacheException;
     }
   }
 }
  private void doTest(boolean strict) {
    EmbeddedCacheManager cm1 = null, cm2 = null;
    try {
      Configuration c = new Configuration();
      c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
      GlobalConfiguration gc = GlobalConfiguration.getClusteredDefault();
      gc.setStrictPeerToPeer(strict);

      cm1 = TestCacheManagerFactory.createCacheManager(gc, c);
      cm2 = TestCacheManagerFactory.createCacheManager(gc, c);

      cm1.getCache();
      cm2.getCache();

      cm1.getCache().put("k", "v");
      assert "v".equals(cm1.getCache().get("k"));
      assert "v".equals(cm2.getCache().get("k"));

      cm1.defineConfiguration("newCache", c);

      if (strict) {
        try {
          cm1.getCache("newCache").put("k", "v");
          assert false : "Should have failed!";
        } catch (CacheException e) {
          assert e.getCause() instanceof NamedCacheNotFoundException;
        }
      } else {
        cm1.getCache("newCache").put("k", "v");
        assert "v".equals(cm1.getCache("newCache").get("k"));
      }
    } finally {
      TestingUtil.killCacheManagers(cm1, cm2);
    }
  }
 public void testMishavingListenerResumesContext() {
   Cache cache = cache(0, "timestamps");
   cache.addListener(new CacheListener());
   try {
     cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).put("k", "v");
   } catch (CacheException ce) {
     assert ce.getCause() instanceof NullPointerException;
   }
 }