Package org.jboss.cache.util.internals.replicationlisteners

Examples of org.jboss.cache.util.internals.replicationlisteners.ReplicationListener


   }


   public void testEvictionOfBackupRegions() throws Exception
   {
      ReplicationListener replicationListener2 = ReplicationListener.getReplicationListener(cache2);
      replicationListener2.expect(PutKeyValueCommand.class);
      cache1.put(fqn, "k", "v");
      replicationListener2.waitForReplicationToOccur();

      assert cache1.peek(fqn, false, false) != null : "Node should exist";
      assert cache2.peek(fqnTransformer.getBackupFqn(cache1.getLocalAddress(), fqn), false, false) != null : "Node should exist on backup";

      // now wait for eviction to kick in - for up to 2 secs
View Full Code Here


   public void testTxCompletion() throws Exception
   {
      AsyncReplTestTL tl = threadLocal.get();
      CacheSPI<Object, Object> cache1 = tl.cache1;
      CacheSPI<Object, Object> cache2 = tl.cache2;
      ReplicationListener replListener1 = tl.replListener1;
      ReplicationListener replListener2 = tl.replListener2;
     
      // test a very simple replication.
      Fqn fqn = Fqn.fromString("/a");
      String key = "key";

      replListener2.expect(PutKeyValueCommand.class);
      cache1.put(fqn, key, "value1");
      // allow for replication
      replListener2.waitForReplicationToOccur();
      assertEquals("value1", cache1.get(fqn, key));
      assertEquals("value1", cache2.get(fqn, key));

      TransactionManager mgr = cache1.getTransactionManager();
      mgr.begin();

      replListener2.expect(PutKeyValueCommand.class);
      cache1.put(fqn, key, "value2");
      assertEquals("value2", cache1.get(fqn, key));
      assertEquals("value1", cache2.get(fqn, key));

      mgr.commit();
      replListener2.waitForReplicationToOccur();

      assertEquals("value2", cache1.get(fqn, key));
      assertEquals("value2", cache2.get(fqn, key));

      mgr.begin();
View Full Code Here

   public void testPutShouldNotReplicateToDifferentCluster()
   {
      AsyncReplTestTL tl = threadLocal.get();
      CacheSPI<Object, Object> cache1 = tl.cache1;
      CacheSPI<Object, Object> cache2 = tl.cache2;
      ReplicationListener replListener1 = tl.replListener1;
      ReplicationListener replListener2 = tl.replListener2;

      CacheSPI<Object, Object> cache3 = null, cache4 = null;
      try
      {
         cache3 = createCache("DifferentGroup");
         cache4 = createCache("DifferentGroup");
         replListener2.expect(PutKeyValueCommand.class);
         cache1.put("/a/b/c", "age", 38);
         // because we use async repl, modfication may not yet have been propagated to cache2, so
         // we have to wait a little
         replListener2.waitForReplicationToOccur(500);
         assertNull("Should not have replicated", cache3.get("/a/b/c", "age"));
      }
      catch (Exception e)
      {
         fail(e.toString());
View Full Code Here

   public void testStateTransfer()
   {
      AsyncReplTestTL tl = threadLocal.get();
      CacheSPI<Object, Object> cache1 = tl.cache1;
      CacheSPI<Object, Object> cache2 = tl.cache2;
      ReplicationListener replListener1 = tl.replListener1;
      ReplicationListener replListener2 = tl.replListener2;

      CacheSPI<Object, Object> cache4 = null;
      try
      {
         cache1.put("a/b/c", "age", 38);
View Full Code Here

   {
      Integer age;
      AsyncReplTestTL tl = threadLocal.get();
      CacheSPI<Object, Object> cache1 = tl.cache1;
      CacheSPI<Object, Object> cache2 = tl.cache2;
      ReplicationListener replListener1 = tl.replListener1;
      ReplicationListener replListener2 = tl.replListener2;

      try
      {
         cache1.put("/a/b/c", "age", 38);
View Full Code Here

   {
      Integer age;
      AsyncReplTestTL tl = threadLocal.get();
      CacheSPI<Object, Object> cache1 = tl.cache1;
      CacheSPI<Object, Object> cache2 = tl.cache2;
      ReplicationListener replListener1 = tl.replListener1;
      ReplicationListener replListener2 = tl.replListener2;

      try
      {
         TransactionManager tm = cache1.getTransactionManager();
         tm.begin();
View Full Code Here

   public void test2InstanceCommit() throws Exception
   {
      groupIncreaser++;
      CacheSPI<Object, Object> cache = createAsyncReplicatedCache();
      CacheSPI<Object, Object> cache2 = createAsyncReplicatedCache();
      ReplicationListener replListener2 = ReplicationListener.getReplicationListener(cache2);
      LockManager lockManager = TestingUtil.extractLockManager(cache);
      LockManager lockManager2 = TestingUtil.extractLockManager(cache2);

      TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
      assertNull(mgr.getTransaction());

      mgr.begin();

      assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
      assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());

      SamplePojo pojo = new SamplePojo(21, "test");

      replListener2.expect(PutKeyValueCommand.class);
      cache.put("/one/two", "key1", pojo);

      mgr.commit();
      replListener2.waitForReplicationToOccur();

      // cache asserts
      assertNull(mgr.getTransaction());
      assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
      assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
View Full Code Here

   public void test2InstanceRemove() throws Exception
   {
      groupIncreaser++;
      CacheSPI<Object, Object> cache = createAsyncReplicatedCache();
      CacheSPI<Object, Object> cache2 = createAsyncReplicatedCache();
      ReplicationListener replListener2 = ReplicationListener.getReplicationListener(cache2);
      LockManager lockManager = TestingUtil.extractLockManager(cache);
      LockManager lockManager2 = TestingUtil.extractLockManager(cache2);

      TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
      assertNull(mgr.getTransaction());

      mgr.begin();

      assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
      assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());

      SamplePojo pojo = new SamplePojo(21, "test");

      replListener2.expect(PutKeyValueCommand.class);
      cache.put("/one/two", "key1", pojo);

      mgr.commit();
      replListener2.waitForReplicationToOccur(1000);

      // cache asserts
      assertNull(mgr.getTransaction());
      assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
      assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());

      assertTrue(cache.exists(Fqn.fromString("/one/two")));
      assertNotNull(cache.getNode("/one"));
      assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));

      assertTrue(cache.exists(Fqn.fromString("/one/two")));
      assertNotNull(cache.getNode("/one"));
      assertEquals(false, lockManager.isLocked(cache.getRoot()));
      assertEquals(false, lockManager.isLocked(cache.getNode("/one")));
      assertEquals(false, lockManager.isLocked(cache.getNode("/one/two")));
      assertNotNull(cache.getNode("/one").getChild("two"));
      assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));

      // cache2 asserts
      assertEquals(0, cache2.getTransactionTable().getNumGlobalTransactions());
      assertEquals(0, cache2.getTransactionTable().getNumLocalTransactions());

      assertTrue(cache2.exists(Fqn.fromString("/one/two")));
      assertNotNull(cache2.getRoot().getChild("one"));
      assertNotNull(cache2.get(Fqn.fromString("/one/two"), "key1"));

      assertTrue(cache2.exists(Fqn.fromString("/one/two")));
      assertNotNull(cache2.getRoot().getChild("one"));
      assertEquals(false, lockManager2.isLocked(cache2.getRoot()));
      assertEquals(false, lockManager2.isLocked(cache2.getNode("/one")));
      assertEquals(false, lockManager2.isLocked(cache2.getNode("/one/two")));
      assertNotNull(cache2.getNode("/one").getChild("two"));
      assertNotNull(cache2.get(Fqn.fromString("/one/two"), "key1"));

      replListener2.expect(RemoveNodeCommand.class);
      replListener2.expect();
      cache.removeNode("/one/two");
      replListener2.waitForReplicationToOccur();

      assertEquals(false, cache.exists("/one/two"));
      assertEquals(null, cache.get("/one/two", "key1"));
      assertEquals(false, cache2.exists("/one/two"));
      assertEquals(null, cache2.get("/one/two", "key1"));
View Full Code Here

   public void testValidationFailCommit2Instances() throws Exception
   {
      groupIncreaser++;
      CacheSPI<Object, Object> cache = createAsyncReplicatedCache();
      ReplicationListener replListener = ReplicationListener.getReplicationListener(cache);
      CacheSPI<Object, Object> cache2 = createAsyncReplicatedCache();
      LockManager lockManager = TestingUtil.extractLockManager(cache);

      TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
      assertNull(mgr.getTransaction());
View Full Code Here

      assertNotSame(mgr2, mgr3);

      assertTrue(mgr1 instanceof DummyTransactionManager);
      assertTrue(mgr2 instanceof DummyTransactionManager);

      ReplicationListener cacheLister2 = ReplicationListener.getReplicationListener(cache2);
      ReplicationListener cacheLister3 = ReplicationListener.getReplicationListener(cache3);

      cacheLister2.expect(PutKeyValueCommand.class);
      cacheLister3.expect(PutKeyValueCommand.class);

      cache1.put("/test", "key", "value");
      cacheLister2.waitForReplicationToOccur();
      cacheLister3.waitForReplicationToOccur();

      assertEquals("value", cache1.get("/test", "key"));
      assertEquals("value", cache2.get("/test", "key"));
      assertEquals("value", cache3.get("/test", "key"));

      mgr3.setNotification(new TestNotification(abortBeforeCompletion));

      cacheLister2.expectWithTx(PutKeyValueCommand.class);
      cacheLister3.expectWithTx(PutKeyValueCommand.class);
      mgr1.begin();
      cache1.put("/test", "key", "value2");
      mgr1.commit();
      cacheLister2.waitForReplicationToOccur();
      cacheLister3.waitForReplicationToOccur();

      // only test cache1 and cache2.  Assume cache3 has crashed out.
      assertEquals(0, cache1.getNumberOfLocksHeld());
      assertEquals(0, cache2.getNumberOfLocksHeld());
      assertEquals("put in transaction should NOT have been rolled back", "value2", cache1.get("/test", "key"));
View Full Code Here

TOP

Related Classes of org.jboss.cache.util.internals.replicationlisteners.ReplicationListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.