Package org.jboss.ejb3.core.test.ejbthree1549

Examples of org.jboss.ejb3.core.test.ejbthree1549.ForceEventsCache


      log.info("Resetting all barriers and clearing the cache...");
      ForceEventsCache.POST_PASSIVATE_BARRIER.reset();
      ForceEventsCache.PRE_PASSIVATE_BARRIER.reset();
      ForceEventsCache.PRE_REMOVE_BARRIER.reset();
      BlockingPersistenceManager.BARRIER.reset();
      ForceEventsCache cache = (ForceEventsCache) container.getCache();
      cache.clear();
   }
View Full Code Here


      // Initialize
      final String sfsbJndiName = MyStatefulLocal.JNDI_NAME;

      // Create a new session, which should be allowed during passivation
      MyStatefulLocal sfsb = (MyStatefulLocal) container.getInitialContext().lookup(sfsbJndiName);

      // If we've got nothing
      if (sfsb == null)
      {
         // Fail
         TestCase.fail("Lookup did not succeed");
      }

      // Invoke upon the new Session
      final int next = sfsb.getNextCounter();

      // Test the value is expected
      TestCase.assertEquals("Next counter received was not expected", 0, next);

      /*
 
View Full Code Here

   }

   @Test
   public void testInvokeSameSessionDuringPassivation() throws Throwable
   {
      final MyStatefulLocal bean = lookup(MyStatefulLocal.JNDI_NAME, MyStatefulLocal.class);

      // Get our bean's Session ID
      Serializable sessionId = this.getSessionId(bean);

      // Invoke upon our bean
      int next = bean.getNextCounter();
      log.info("Got counter from " + sessionId + ": " + next);
      TestCase.assertEquals("SFSB did not return expected next counter", 0, next);

      // Get the Cache
      ForceEventsCache cache = (ForceEventsCache) container.getCache();

      // Get the lock to block the PM, now
      boolean gotLock = BlockingPersistenceManager.PASSIVATION_LOCK.tryLock();

      Future<Integer> result;
      // Once PM lock is acquired, everything is in "try" so we release in "finally"
      try
      {
         // Ensure we got the PM lock, else fail the test
         TestCase.assertTrue("Test was not able to immediately get the lock to block the PersistenceManager", gotLock);
         log.info("Locked " + BlockingPersistenceManager.class.getSimpleName());

         // Mark
         cache.makeSessionEligibleForPassivation(sessionId);

         /*
          * Passivate
          */

         // Trigger Passivation
         ForceEventsCache.forcePassivation();
         log.info("Passivation forced, carrying out test");

         ForceEventsCache.PRE_PASSIVATE_BARRIER.await(5, TimeUnit.SECONDS);

         // Block until the PM is ready to passivate
         log.info("Waiting on common barrier for PM to run...");
         BlockingPersistenceManager.BARRIER.await(5, TimeUnit.SECONDS);
         log.info("PM and test have met barrier, passivation running (but will be blocked to complete by test)");

         Callable<Integer> task = new Callable<Integer>()
         {
            public Integer call() throws Exception
            {
               return bean.getNextCounter();
            }
         };
         ExecutorService executor = Executors.newFixedThreadPool(1);
         result = executor.submit(task);

         // TODO: there is no way to know where we are in StatefulInstanceInterceptor
         Thread.sleep(5000);
      }
      finally
      {
         // Allow the Persistence Manager to finish up
         log.info("Letting the PM perform passivation...");
         BlockingPersistenceManager.PASSIVATION_LOCK.unlock();
      }

      // We need to allow time to let the Cache finish passivation, so block until it's done
      log.info("Waiting on Cache to tell us passivation is completed...");
      ForceEventsCache.POST_PASSIVATE_BARRIER.await(5, TimeUnit.SECONDS);
      log.info("Test sees Cache reports passivation completed.");

      int duringPassivation = result.get(5, TimeUnit.SECONDS);
      log.info("Got counter from " + sessionId + ": " + duringPassivation);

      int postPassivation = bean.getNextCounter();
      log.info("Got counter from " + sessionId + ": " + postPassivation);

      assertEquals("the postPassivation counter should be 1 higher than the previous (during passivation)",
            duringPassivation + 1, postPassivation);
   }
View Full Code Here

   }

   @Test
   public void testInvokeSameSessionDuringPrePassivation() throws Throwable
   {
      final MyStatefulLocal bean = lookup(MyStatefulLocal.JNDI_NAME, MyStatefulLocal.class);

      // Get our bean's Session ID
      Serializable sessionId = this.getSessionId(bean);

      // Invoke upon our bean
      int next = bean.getNextCounter();
      log.info("Got counter from " + sessionId + ": " + next);
      TestCase.assertEquals("SFSB did not return expected next counter", 0, next);

      // Get the Cache
      ForceEventsCache cache = (ForceEventsCache) container.getCache();

      // Get the lock to block the PM, now
      boolean gotLock = BlockingPersistenceManager.PASSIVATION_LOCK.tryLock();

      Future<Integer> result;
      // Once PM lock is acquired, everything is in "try" so we release in "finally"
      try
      {
         // Ensure we got the PM lock, else fail the test
         TestCase.assertTrue("Test was not able to immediately get the lock to block the PersistenceManager", gotLock);
         log.info("Locked " + BlockingPersistenceManager.class.getSimpleName());

         // Mark
         cache.makeSessionEligibleForPassivation(sessionId);

         /*
          * Passivate
          */

         // Trigger Passivation
         ForceEventsCache.forcePassivation();
         log.info("Passivation forced, carrying out test");

         Callable<Integer> task = new Callable<Integer>()
         {
            public Integer call() throws Exception
            {
               return bean.getNextCounter();
            }
         };
         ExecutorService executor = Executors.newFixedThreadPool(1);
         result = executor.submit(task);

         // TODO: there is no way to know where we are in StatefulInstanceInterceptor
         Thread.sleep(5000);

         ForceEventsCache.PRE_PASSIVATE_BARRIER.await(5, TimeUnit.SECONDS);

         // Block until the PM is ready to passivate
         /* we're not passivating, we yanked it out
         log.info("Waiting on common barrier for PM to run...");
         BlockingPersistenceManager.BARRIER.await(5, TimeUnit.SECONDS);
         log.info("PM and test have met barrier, passivation running (but will be blocked to complete by test)");
         */
      }
      finally
      {
         // Allow the Persistence Manager to finish up
         log.info("Letting the PM perform passivation...");
         BlockingPersistenceManager.PASSIVATION_LOCK.unlock();
      }

      // We need to allow time to let the Cache finish passivation, so block until it's done
      log.info("Waiting on Cache to tell us passivation is completed...");
      ForceEventsCache.POST_PASSIVATE_BARRIER.await(5, TimeUnit.SECONDS);
      log.info("Test sees Cache reports passivation completed.");

      int duringPassivation = result.get(5, TimeUnit.SECONDS);
      log.info("Got counter from " + sessionId + ": " + duringPassivation);

      int postPassivation = bean.getNextCounter();
      log.info("Got counter from " + sessionId + ": " + postPassivation);

      assertEquals("the postPassivation counter should be 1 higher than the previous (during passivation)",
            duringPassivation + 1, postPassivation);
   }
View Full Code Here

         public Boolean call()
         {
            try
            {
               // Create a new session, which should be allowed during passivation
               MyStatefulLocal bean2 = (MyStatefulLocal) container.getInitialContext().lookup(sfsbJndiName);

               // If we've don't have a new session
               if (bean2 == null)
               {
                  throw new RuntimeException("Got back null SFSB");
View Full Code Here

         public Boolean call()
         {
            try
            {
               // Create a new session, which should be allowed during passivation
               MyStatefulLocal bean2 = (MyStatefulLocal) container.getInitialContext().lookup(sfsbJndiName);

               // If we've got nothing
               if (bean2 == null)
               {
                  // Let test fail, logging along the way
                  log.error("Lookup did not succeed");
               }

               // Invoke upon the new Session
               int next = bean2.getNextCounter();

               // Test the value
               if (next == 0)
               {
                  return true;
View Full Code Here

      // Initialize
      final String sfsbJndiName = MyStatefulLocal.JNDI_NAME;
      boolean testSucceeded = false;

      // Lookup an instance
      MyStatefulLocal bean1 = (MyStatefulLocal) container.getInitialContext().lookup(sfsbJndiName);

      // Invoke upon our bean
      int next = bean1.getNextCounter();
      log.info("Got counter from bean1 : " + next);
      TestCase.assertEquals("SFSB did not return expected next counter", 0, next);

      // Get our bean's Session ID
      Serializable sessionId = this.getSessionId(bean1);
View Full Code Here

      //DeploymentScope scope = null;
      if (unit.getParent() != null)
      {
         boolean isEar = unit != unit.getTopLevel();
         this.deploymentScope = new JBoss5DeploymentScope(unit.getParent(), isEar);
      }

      ejbResolver = new ClientEjbResolver(deploymentScope, unit.getSimpleName());
      messageDestinationResolver = new MessageDestinationResolver(deploymentScope, xml.getMessageDestinations());
View Full Code Here

         throw new NullPointerException("applicationClientName is mandatory");
      if (classLoader == null)
         throw new NullPointerException("classLoader is mandatory");

      this.deploymentUnit = unit;
      this.ejb3Unit = new JBoss5DeploymentUnit(unit);
      this.clientMetaData = xml;
      this.mainClass = mainClass;
      this.applicationClientName = applicationClientName;
      this.classLoader = classLoader;
View Full Code Here

    * @param shortName
    */
   public JBoss5DeploymentScope(VFSDeploymentUnit parent, boolean isEar, String shortName)
   {
      this(parent, isEar);
      ejbRefResolver = new EjbModuleEjbResolver(this, shortName);
   }
View Full Code Here

TOP

Related Classes of org.jboss.ejb3.core.test.ejbthree1549.ForceEventsCache

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.