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

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


     
      String contextHostName = mgr0.getContextHostName();

      // Create the session
      SetAttributesServlet sas = new SetAttributesServlet(Collections.singletonMap(KEY, getAttributeValue(attr++)));
      ReplicationListener replListener0 = replListeners[0];
      replListener0.expectWithTx(PutDataMapCommand.class);
     
      Request req = new Request(mgr3, null, sas);
      req.execute();     
      replListener0.waitForReplicationToOccur();     
     
      String sessionId = sas.getSessionId();
      assert sessionId != null : "session id is null";
      // validate cache contents
      BuddyReplicationAssertions.assertBuddyBackup(contextHostName, sessionId, mgr3.getCache(), mgr0.getCache());
     
      // Modify the session
      sas = new SetAttributesServlet(Collections.singletonMap(KEY, getAttributeValue(attr++)));
      replListener0.expectWithTx(PutDataMapCommand.class);
     
      req = new Request(mgr3, sessionId, sas);
      req.execute();     
      replListener0.waitForReplicationToOccur();     

      // Passivate the session
      mgr0.passivate(sessionId);
      mgr1.passivate(sessionId);
      mgr2.passivate(sessionId);
      mgr3.passivate(sessionId);  
     
      // Reactivate the session
      sas = new SetAttributesServlet(Collections.singletonMap(KEY, getAttributeValue(attr++)));
      replListener0.expectWithTx(PutDataMapCommand.class);
     
      req = new Request(mgr3, sessionId, sas);
      req.execute();
      replListener0.waitForReplicationToOccur();     

      // Invalidate the session
      sas = new SetAttributesServlet(Collections.singletonMap(KEY, getAttributeValue(attr++)));
      InvalidationServlet invs = new InvalidationServlet();
      MultipleActionServlet mas = new MultipleActionServlet(sas, invs);
      ReplicationListener replListener1 = replListeners[1];
      replListener1.expectWithTx(PutDataMapCommand.class, RemoveNodeCommand.class);
      replListener1.expect(DataGravitationCleanupCommand.class);

      req = new Request(mgr0, sessionId, mas);
      req.execute();     
      replListener1.waitForReplicationToOccur();

      TestingUtil.dumpCacheContents(mgr0.getCache(), mgr1.getCache(), mgr2.getCache(), mgr3.getCache());

      BuddyReplicationAssertions.assertUnrelated(contextHostName, sessionId, mgr0.getCache());
      BuddyReplicationAssertions.assertUnrelated(contextHostName, sessionId, mgr1.getCache());
View Full Code Here


   }

   public void testPessAsyncRepl() throws Exception
   {
      createCaches(false, false);
      ReplicationListener replListener = ReplicationListener.getReplicationListener(cache2);

      mgr1.begin();
      cache1.put(fqn, key, "value");

      assertEquals("value", cache1.get(fqn, key));
      assertNull(cache2.get(fqn, key));
      assertNull(loader1.get(fqn));
      assertNull(loader2.get(fqn));

      replListener.expectWithTx(PutKeyValueCommand.class);
      mgr1.commit();
      replListener.waitForReplicationToOccur();

      assertEquals("value", cache1.get(fqn, key));
      assertEquals("value", cache2.get(fqn, key));
      assertEquals("value", loader1.get(fqn).get(key));
      assertEquals("value", loader2.get(fqn).get(key));
View Full Code Here

   public void testOptAsyncRepl() throws Exception
   {
      createCaches(false, true);

      ReplicationListener replListener = ReplicationListener.getReplicationListener(cache2);

      mgr1.begin();
      replListener.expectWithTx(PutKeyValueCommand.class);
      cache1.put(fqn, key, "value");

      assertEquals("value", cache1.get(fqn, key));
      assertNull(cache2.get(fqn, key));
      assertNull(loader1.get(fqn));
      assertNull(loader2.get(fqn));

      mgr1.commit();

      replListener.waitForReplicationToOccur();

      assertEquals("value", cache1.get(fqn, key));
      assertEquals("value", cache2.get(fqn, key));
      assertEquals("value", loader1.get(fqn).get(key));
      assertEquals("value", loader2.get(fqn).get(key));
View Full Code Here

      assertTrue(!caches.get(2).exists(backupFqn2));

      assertNoLocks(caches);

      // gravitate to 2:
      ReplicationListener replListener0 = ReplicationListener.getReplicationListener(caches.get(0));
      ReplicationListener replListener1 = ReplicationListener.getReplicationListener(caches.get(1));
      replListener0.expect(DataGravitationCleanupCommand.class);
      replListener1.expect(DataGravitationCleanupCommand.class);
      caches.get(2).getNode(fqn)// expectWithTx entire subtree to gravitate.
      replListener0.waitForReplicationToOccur(); // cleanup commands are async
      replListener1.waitForReplicationToOccur(); // also wait untill the backup is cleaned

      Fqn newBackupFqn = fqnTransformer.getBackupFqn(caches.get(2).getLocalAddress(), fqn);
      Fqn newBackupFqn2 = fqnTransformer.getBackupFqn(caches.get(2).getLocalAddress(), fqn2);

      assertEquals(value, caches.get(2).get(fqn, key));
View Full Code Here

      Fqn fqn = Fqn.fromString("/test");
      Fqn backupFqn = fqnTransformer.getBackupFqn(caches.get(2).getLocalAddress(), fqn);

      TestingUtil.dumpCacheContents(caches);

      ReplicationListener replListener0 = ReplicationListener.getReplicationListener(caches.get(0));

      replListener0.expect(PutKeyValueCommand.class);
      caches.get(2).put(fqn, key, value);
      replListener0.waitForReplicationToOccur();


      TestingUtil.dumpCacheContents(caches);

      assertEquals("Value should exist", value, caches.get(2).get(fqn, key));

      TestingUtil.dumpCacheContents(caches);

      // use exists instead of get() to prevent going up the interceptor stack
      assertTrue("Should be false", !caches.get(0).exists(fqn));
      assertTrue("Should be false", !caches.get(1).exists(fqn));

      assertTrue("Value be true", caches.get(0).exists(backupFqn));
      assertFalse("Should be false", caches.get(1).exists(backupFqn));
      assertFalse("Should be false", caches.get(2).exists(backupFqn));

      Address cache2Addr = caches.get(2).getLocalAddress();
      // forcefully kill data owner.
      caches.get(2).stop();
      caches.get(2).destroy();
      TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
      waitForSingleBuddy(caches.get(0), caches.get(1));

//      TestingUtil.dumpCacheContents(cachePool);
      // assert that the remaining cachePool have picked new buddies.  Cache 1 should have cache 2's backup data.
      assert caches.get(0).peek(fqnTransformer.getBackupRoot(caches.get(1).getLocalAddress()), false) != null : "Should have new buddy's backup root.";
      assert caches.get(1).peek(fqnTransformer.getBackupRoot(caches.get(1).getLocalAddress()), false) == null : "Should not have self as a backup root.";
      assert caches.get(0).peek(fqnTransformer.getBackupRoot(cache2Addr), false) == null : "Should not have dead node as a backup root.";
      assert caches.get(0).peek(Fqn.fromRelativeElements(fqnTransformer.getDeadBackupRoot(cache2Addr), 1), false) != null : "Should have dead node as a defunct backup root.";

      assert caches.get(1).peek(fqnTransformer.getBackupRoot(caches.get(1).getLocalAddress()), false) == null : "Should not have self as a backup root.";
      assert caches.get(1).peek(fqnTransformer.getBackupRoot(caches.get(0).getLocalAddress()), false) != null : "Should have new buddy's backup root.";
      assert caches.get(1).peek(fqnTransformer.getBackupRoot(cache2Addr), false) == null : "Should not have dead node as a backup root.";
      assert caches.get(1).peek(Fqn.fromRelativeElements(fqnTransformer.getDeadBackupRoot(cache2Addr), 1), false) == null : "Should not have dead node as a defunct backup root.";


      replListener0.expect(DataGravitationCleanupCommand.class);

      // according to data gravitation, a call to *any* cache should retrieve the data, and move the data to the new cache.
      assertEquals("Value should have gravitated", value, caches.get(1).get(fqn, key));
      replListener0.waitForReplicationToOccur();

      // use exists instead of get() to prevent going up the interceptor stack
      assert caches.get(0).peek(fqnTransformer.getBackupRoot(caches.get(1).getLocalAddress()), false) != null : "Should have new buddy's backup root.";
      assert caches.get(0).peek(fqnTransformer.getBackupRoot(caches.get(0).getLocalAddress()), false) == null : "Should not have self as a backup root.";
      assert caches.get(0).peek(fqnTransformer.getBackupRoot(cache2Addr), false) == null : "Should not have dead node as a backup root.";
View Full Code Here

         Fqn fqn = Fqn.fromString("/a/b/c");

         assert  null == cache0.get(fqn, "k");
         cache0.put(fqn, "key", "val");

         ReplicationListener replicationListener = ReplicationListener.getReplicationListener(cache0);
         replicationListener.expect(DataGravitationCleanupCommand.class);
         TransactionManager transactionManager = cache1.getTransactionManager();

         transactionManager.begin();
         assert cache1.get(fqn, "key").equals("val");
         transactionManager.commit();
         replicationListener.waitForReplicationToOccur(1000);

         assert !cache0.exists(fqn);

      } finally
      {
View Full Code Here

   public void createCaches() throws Exception
   {
      caches = createCaches(3, false, false);
      for (Cache c : caches)
      {
        ReplicationListener listener = ReplicationListener.getReplicationListener(c);
        replListener.add(listener);
      }
   }
View Full Code Here

   private void dataGravitationEvictionTest(boolean autoGravitate) throws Exception
   {
      // create 3 cachePool
      List<CacheSPI<Object, Object>> caches = createCachesWithCacheLoader(3, autoGravitate, false, passivation);
      ReplicationListener replListener0 = ReplicationListener.getReplicationListener(caches.get(0));
      ReplicationListener replListener1 = ReplicationListener.getReplicationListener(caches.get(1));
      ReplicationListener replListener2 = ReplicationListener.getReplicationListener(caches.get(2));

      cachesTL.set(caches);
      CacheLoader[] loaders = getLoaders(caches);
      Fqn b1 = fqnTransformer.getBackupFqn(caches.get(0).getLocalAddress(), fqn);
      Fqn b2 = fqnTransformer.getBackupFqn(caches.get(2).getLocalAddress(), fqn);
View Full Code Here

      cache2 = null;
   }

   public void testTransactionalReplication() throws Exception
   {
      ReplicationListener cache1Listener = ReplicationListener.getReplicationListener(cache);
      ReplicationListener cache2Listener = ReplicationListener.getReplicationListener(cache2);

      cache2Listener.expect(PutKeyValueCommand.class);
      // outside of tx scope
      cache.put("/a", "k", "v");
      cache2Listener.waitForReplicationToOccur(5000);

      assert cache2.get("/a", "k").equals("v");

      // now, a transactional call
      cache1Listener.expect(PrepareCommand.class);
View Full Code Here

         {
            BuddyReplicationTestsBase.waitForSingleBuddy(cache1, cache2);
            Set backupNameSet = new HashSet(nameSet);
            backupNameSet.remove(BuddyFqnTransformer.BUDDY_BACKUP_SUBTREE);

            ReplicationListener replListener1 = ReplicationListener.getReplicationListener(cache1);
            replListener1.expect(DataGravitationCleanupCommand.class);
            cache2.getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
            Node backupNode = cache2.getNode(fqn);
            replListener1.waitForReplicationToOccur();

           assert backupNode.getChildrenNames().equals(backupNameSet) : "Expecting " + backupNameSet + " but got " + backupNode.getChildrenNames();
         }
         else
         {
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.