private void doTest(boolean mods) throws Exception {
    // force the prepare command to fail on c2
    FailInterceptor interceptor = new FailInterceptor();
    interceptor.failFor(PrepareCommand.class);
    InterceptorChain ic = TestingUtil.extractComponent(c2, InterceptorChain.class);
    ic.addInterceptorBefore(interceptor, TxDistributionInterceptor.class);

    MagicKey k1 = new MagicKey("k1", c1);
    MagicKey k2 = new MagicKey("k2", c2);

    tm(c1).begin();
    if (mods) {
      c1.put(k1, "v1");
      c1.put(k2, "v2");

      assertKeyLockedCorrectly(k1);
      assertKeyLockedCorrectly(k2);
    } else {
      c1.getAdvancedCache().lock(k1);
      c1.getAdvancedCache().lock(k2);

      assertNull(c1.get(k1));
      assertNull(c1.get(k2));

      assertKeyLockedCorrectly(k1);
      assertKeyLockedCorrectly(k2);
    }

    try {
      tm(c1).commit();
      assert false : "Commit should have failed";
    } catch (Exception e) {
      // expected
    }

    assertNotLocked(c1, k1);
    assertNotLocked(c2, k1);
    assertNotLocked(c1, k2);
    assertNotLocked(c2, k2);
  }
Пример #2
0
 public void addInterceptorBefore(
     CommandInterceptor i, Class<? extends CommandInterceptor> beforeInterceptor) {
   invoker.addInterceptorBefore(i, beforeInterceptor);
 }