Package org.jboss.cache.util.internals

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


   {
      AsyncReplTestTL tl = new AsyncReplTestTL();
      threadLocal.set(tl);
      log("creating cache1");
      tl.cache1 = createCache("CacheGroup");
      tl.replListener1 = new ReplicationListener(tl.cache1);

      log("creating cache2");
      tl.cache2 = createCache("CacheGroup");
      tl.replListener2 = new ReplicationListener(tl.cache2);
   }
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.expectAny();
      cache1.put(fqn, key, "value1");
      // allow for replication
      replListener2.waitForReplicationToOccur(500);
      assertEquals("value1", cache1.get(fqn, key));
      assertEquals("value1", cache2.get(fqn, key));

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

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

      mgr.commit();

      replListener2.waitForReplicationToOccur(500);

      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.expectAny();
         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

      cache2.getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_ASYNC);
      cache1.start();
      cache2.start();

      Fqn fqn = Fqn.fromString("/a/b");
      ReplicationListener replListener1 = new ReplicationListener(cache1);
      ReplicationListener replListener2 = new ReplicationListener(cache2);

      replListener2.expectAny();
      cache1.put(fqn, "key", "value");
      replListener2.waitForReplicationToOccur(500);
//      TestingUtil.sleepThread(500);// give it time to broadcast the evict call
      // test that this has NOT replicated, but rather has been invalidated:
      assertEquals("value", cache1.get(fqn, "key"));
      assertNull("Should NOT have replicated!", cache2.getNode(fqn));

      replListener1.expectAny();
      // now make sure cache2 is in sync with cache1:
      cache2.put(fqn, "key", "value");
//      TestingUtil.sleepThread(500);// give it time to broadcast the evict call
      replListener1.waitForReplicationToOccur(500);

      // since the node already exists even PL will not remove it - but will invalidate it's data
      Node n = cache1.getNode(fqn);
      assertHasBeenInvalidated(n, "Should have been invalidated");
      assertEquals("value", cache2.get(fqn, "key"));

      replListener2.expectAny();
      // now test the invalidation:
      cache1.put(fqn, "key2", "value2");
      assertEquals("value2", cache1.get(fqn, "key2"));
//      TestingUtil.sleepThread(500);// give it time to broadcast the evict call
      replListener2.waitForReplicationToOccur(500);

      // since the node already exists even PL will not remove it - but will invalidate it's data
      n = cache2.getNode(fqn);
      assertHasBeenInvalidated(n, "Should have been invalidated");
   }
View Full Code Here

   public void test2InstanceCommit() throws Exception
   {
      groupIncreaser++;
      CacheSPI<Object, Object> cache = createAsyncReplicatedCache();
      CacheSPI<Object, Object> cache2 = createAsyncReplicatedCache();
      ReplicationListener replListener2 = new ReplicationListener(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.expectAny();
      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());
View Full Code Here

   public void test2InstanceRemove() throws Exception
   {
      groupIncreaser++;
      CacheSPI<Object, Object> cache = createAsyncReplicatedCache();
      CacheSPI<Object, Object> cache2 = createAsyncReplicatedCache();
      ReplicationListener replListener2 = new ReplicationListener(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, CommitCommand.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(CommitCommand.class);
      cache.removeNode("/one/two");
      replListener2.waitForReplicationToOccur(1000);

      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 = new ReplicationListener(cache);
      CacheSPI<Object, Object> cache2 = createAsyncReplicatedCache();
      LockManager lockManager = TestingUtil.extractLockManager(cache);

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

TOP

Related Classes of org.jboss.cache.util.internals.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.