Package org.jboss.cache.aop.test

Examples of org.jboss.cache.aop.test.Person


   public void testSimpleTxWithRollback() throws Exception
   {
      log.info("testSimpleTxWithRollback() ....");
      UserTransaction tx = getTransaction();

      Person joe = new Person();
      joe.setName("Joe");
      Address add = new Address();
      add.setZip(104);
      add.setCity("Taipei");
      joe.setAddress(add);

      tx.begin();
      cache_.putObject("/person/joe", joe);
      tx.commit();
      Person p = (Person)cache1_.getObject("/person/joe");
      assertEquals("Zip should be the same ", joe.getAddress().getZip(), p.getAddress().getZip());

      // test rollback
      Person ben = new Person();
      ben.setName("Ben");
      add = new Address();
      add.setZip(104);
      add.setCity("Taipei");
      joe.setAddress(add);
      tx.begin();
View Full Code Here


   public void testCollectionTxWithRollback() throws Exception
   {
      log.info("testCollectionTxWithRollback() ....");
      UserTransaction tx = getTransaction();

      Person joe = new Person();
      joe.setName("Joe");
      Address add = new Address();
      add.setZip(104);
      add.setCity("Taipei");
      joe.setAddress(add);
      ArrayList lang = new ArrayList();
      lang.add("English");
      lang.add("Taiwanese");
      lang.add("Mandirin");
      joe.setLanguages(lang);

      tx.begin();
      cache_.putObject("/person/joe", joe);
      tx.commit();
      Person p = (Person)cache1_.getObject("/person/joe");
      assertEquals("Zip should be the same ", joe.getAddress().getZip(), p.getAddress().getZip());

      // test rollback
      Person ben = new Person();
      ben.setName("Ben");
      add = new Address();
      add.setZip(104);
      add.setCity("Taipei");
      ben.setAddress(add);
      tx.begin();
      cache_.putObject("/person/ben", ben);
      tx.rollback();
      assertEquals("Zip should be the same ", joe.getAddress().getZip(), p.getAddress().getZip());
      assertEquals("Langue 1 should be: ", "English", (String)joe.getLanguages().get(0));
View Full Code Here

   {
      Thread t1 = new Thread()
      {
         public void run()
         {
            Person p = new Person();
            p.setName("Ben");
            Address add = new Address();
            add.setCity("Taipei");
            p.setAddress(add);
            List  lang = new ArrayList();
            lang.add("English");
            lang.add("Taiwanese");
            lang.add("Japanese");
            p.setLanguages(lang);
            try {
               cache_.putObject("/test/ben", p);
            }
            catch(Exception ex) {
               try {
                  cache_.putObject("/test/ben", p);
               } catch (Exception ex1)
               {
                  t1_ex = ex1;
               }
            }
         }
      };

      Thread t2 = new Thread()
      {
         Transaction tx;
         public void run()
         {
            try {
               UserTransaction tx = getTransaction();
               tx.begin();
               Person p = new Person();
               p.setName("Ben");
               Address add = new Address();
               add.setCity("Taipei");
               p.setAddress(add);
               cache1_.putObject("/test/ben", p);
               TestingUtil.sleepThread(1000);
               tx.commit();
            }
            catch(RollbackException rollback) {
View Full Code Here

         Transaction tx;

         public void run()
         {
            UserTransaction tx = null;
            Person p = new Person();
            p.setName("Ben");
            Address add = new Address();
            add.setCity("Taipei");
            p.setAddress(add);
            List  lang = new ArrayList();
            lang.add("English");
            lang.add("Taiwanese");
            lang.add("Japanese");
            p.setLanguages(lang);
            try {
               tx = getTransaction();
               tx.begin();
               cache_.putObject("/test/ben", p);
               TestingUtil.sleepThread(1000);
               tx.commit();
            }
            catch(RollbackException rollback) {
               try {
                  tx = getTransaction();
                  tx.begin();
                  cache_.putObject("/test/ben", p);
                  tx.commit();
               } catch (Exception ex)
               {
                  t1_ex = ex;
                  ex.printStackTrace();
               }
            }
            catch (Exception ex) {
               t1_ex = ex;
               ex.printStackTrace();
            }
         }
      };

      Thread t2 = new Thread()
      {
         Transaction tx;

         public void run()
         {
            try {
               UserTransaction tx = getTransaction();
               tx.begin();
               Person p = new Person();
               p.setName("Ben");
               Address add = new Address();
               add.setCity("Taipei");
               p.setAddress(add);
               cache1_.putObject("/test/ben", p);
               TestingUtil.sleepThread(1000);
               tx.commit();
            }
            catch(RollbackException rollback) {
View Full Code Here

         fail("Thread2 failed: " + t2_ex);
   }

   public void testConcurrentTxPutsWithRollbackField() throws Exception
   {
      Person p = new Person();
      p.setName("Ben");
      Address add = new Address();
      add.setCity("Taipei");
      p.setAddress(add);
      List  lang = new ArrayList();
      IdObject id1 = new IdObject("1");
      lang.add(id1);
      p.setLanguages(lang);
      cache_.putObject("/test/ben", p);

      Thread t1 = new Thread()
      {
         Transaction tx;

         public void run()
         {
            UserTransaction tx = null;
            List lang = null;
            IdObject id2 = new IdObject("2");
            IdObject id3 = new IdObject("3");
            try {
               Person ben = (Person)cache_.getObject("/test/ben");
               lang = ben.getLanguages();

               tx = getTransaction();
               tx.begin();
               lang.add(id2);
               lang.add(id3);
               lang.remove(0);
               TestingUtil.sleepThread(1000);
               tx.commit();
            }
            catch(RollbackException rollback) {
               try {
                  tx = getTransaction();
                  tx.begin();
                  lang.add(id2);
                  lang.add(id3);
                  lang.remove(0);
                  tx.commit();
               } catch (Exception ex)
               {
                  t1_ex = ex;
               }
            }
            catch (Exception ex) {
               t1_ex = ex;
            }
         }
      };

      Thread t2 = new Thread()
      {
         Transaction tx;

         public void run()
         {
            List lang = null;
            UserTransaction tx = null;
            IdObject id1 = null;
            try {
               Person ben = (Person)cache1_.getObject("/test/ben");
               lang = ben.getLanguages();

               tx = getTransaction();
               tx.begin();
               id1 = new IdObject("2");
               lang.add(id1);
View Full Code Here

      // Pause to give caches time to see each other
      TestingUtil.blockUntilViewsReceived(new PojoCache[]
      {cache1, cache2}, 60000);

      Person ab1  = (Person) cache2.getObject(A_B_1);
      Person ab2 = (Person) cache2.getObject(A_B_2);
      Person ac1  = (Person) cache2.getObject(A_C_1);
      Person ac2 = (Person) cache2.getObject(A_C_2);
      assertEquals("Name for /a/b/1 is Joe", joe.getName(), ab1.getName());
      assertEquals("City for /a/b/1 is Anytown", addr1.getCity(), ab1.getAddress().getCity());
      assertEquals("Name for /a/b/2 is Jane", jane.getName(), ab2.getName());
      assertEquals("City for /a/b/2 is Anytown", addr1.getCity(), ab2.getAddress().getCity());
      assertTrue("Joe and Jane have same Address", ab1.getAddress() == ab2.getAddress());
      assertEquals("Name for /a/c/1 is Bob", bob.getName(), ac1.getName());
      assertEquals("City for /a/c/1 is Fremont", addr2.getCity(), ac1.getAddress().getCity());
      assertEquals("Name for /a/c/2 is Jill", jill.getName(), ac2.getName());
      assertEquals("City for /a/c/2 is Fremont", addr2.getCity(), ac2.getAddress().getCity());
      assertTrue("Bob and Jill have same Address", ac1.getAddress() == ac2.getAddress());
   }
View Full Code Here

      assertEquals("Loader name for /a/b/1 is Joe", joe.getName(), loader.get(A_B_1).get("name"));
      assertEquals("Loader name for /a/b/2 is Jane", jane.getName(), loader.get(A_B_2).get("name"));
      assertEquals("Loader name for /a/c/1 is Joe", bob.getName(), loader.get(A_C_1).get("name"));
      assertEquals("Loader name for /a/c/2 is Jill", jill.getName(), loader.get(A_C_2).get("name"));
     
      Person ab1  = (Person) cache2.getObject(A_B_1);
      Person ab2 = (Person) cache2.getObject(A_B_2);
      Person ac1  = (Person) cache2.getObject(A_C_1);
      Person ac2 = (Person) cache2.getObject(A_C_2);
      assertEquals("Name for /a/b/1 is Joe", joe.getName(), ab1.getName());
      assertEquals("City for /a/b/1 is Anytown", addr1.getCity(), ab1.getAddress().getCity());
      assertEquals("Name for /a/b/2 is Jane", jane.getName(), ab2.getName());
      assertEquals("City for /a/b/2 is Anytown", addr1.getCity(), ab2.getAddress().getCity());
      assertTrue("Joe and Jane have same Address", ab1.getAddress() == ab2.getAddress());
      assertEquals("Name for /a/c/1 is Bob", bob.getName(), ac1.getName());
      assertEquals("City for /a/c/1 is Fremont", addr2.getCity(), ac1.getAddress().getCity());
      assertEquals("Name for /a/c/2 is Jill", jill.getName(), ac2.getName());
      assertEquals("City for /a/c/2 is Fremont", addr2.getCity(), ac2.getAddress().getCity());
      assertTrue("Bob and Jill have same Address", ac1.getAddress() == ac2.getAddress());
   }
View Full Code Here

      assertNull("/a/b/1 not transferred per policy", cache2.getObject(A_B_1));
      assertNull("/a/b/2 not transferred per policy", cache2.getObject(A_B_2));

      cache2.activateRegion("/a/b");
     
      Person ab1  = (Person) cache2.getObject(A_B_1);
      Person ab2 = (Person) cache2.getObject(A_B_2);
      assertEquals("Name for /a/b/1 is Joe", joe.getName(), ab1.getName());
      assertEquals("City for /a/b/1 is Anytown", joe.getAddress().getCity(), ab1.getAddress().getCity());
      assertEquals("Name for /a/b/2 is Jane", jane.getName(), ab2.getName());
      assertEquals("City for /a/b/2 is Anytown", jane.getAddress().getCity(), ab2.getAddress().getCity());     
      assertTrue("Address for Joe and Jane is the same object", ab1.getAddress() == ab2.getAddress());

      cache1.putObject(A_C_1, bob);
      cache1.putObject(A_C_2, jill);
     
      assertNull("/a/c/1 not transferred per policy", cache2.getObject(A_C_1));

      cache2.activateRegion("/a/c");
     
      Person ac1 = (Person) cache2.getObject(A_C_1);
      Person ac2 = (Person) cache2.getObject(A_C_2);
      assertEquals("Name for /a/c/1 is Bob", bob.getName(), ac1.getName());
      assertEquals("City for /a/c/1 is Fremont", addr2.getCity(), ac1.getAddress().getCity());
      assertEquals("Name for /a/c/2 is Jill", jill.getName(), ac2.getName());
      assertEquals("City for /a/c/2 is Fremont", addr2.getCity(), ac2.getAddress().getCity());
      assertTrue("Bob and Jill have same Address", ac1.getAddress() == ac2.getAddress());

      cache1.inactivateRegion("/a");

      cache1.activateRegion("/a/b/1");
      cache1.activateRegion("/a/b/2");
      cache1.activateRegion("/a/c/1");
      cache1.activateRegion("/a/c/2");

      ab1  = (Person) cache1.getObject(A_B_1);
      assertEquals("Name for /a/b/1 is Joe", joe.getName(), ab1.getName());
      assertEquals("City for /a/b/1 is Anytown", addr1.getCity(), ab1.getAddress().getCity());
      ab2 = (Person) cache1.getObject(A_B_2);;
      assertEquals("Name for /a/b/1 is Jane", jane.getName(), ab2.getName());
      assertEquals("City for /a/b/1 is Anytown", addr1.getCity(), ab2.getAddress().getCity());
      assertTrue("Address for Joe and Jane is the same object", ab1.getAddress() == ab2.getAddress());
      ac1 = (Person) cache1.getObject(A_C_1);
      assertEquals("Name for /a/c/1 is Bob", bob.getName(), ac1.getName());
      assertEquals("City for /a/c/1 is Fremont", addr2.getCity(), ac1.getAddress().getCity());
      ac2 = (Person) cache1.getObject(A_C_2);
      assertEquals("Name for /a/c/2 is Jill", jill.getName(), ac2.getName());
      assertEquals("City for /a/c/2 is Fremont", addr2.getCity(), ac2.getAddress().getCity());
      assertTrue("Address for Bob and Jill is the same object", ac1.getAddress() == ac2.getAddress());
   }
View Full Code Here

      assertEquals("Correct age from loader for /a/b/1", TWENTY, loader.get(A_B_1).get("age"));
      assertEquals("Correct name from loader for /a/b/2", jane.getName(), loader.get(A_B_2).get("name"));
      assertEquals("Correct age from loader for /a/b/2", TWENTYFIVE, loader.get(A_B_2).get("age"));
     
     
      Person ab1  = (Person) cache2.getObject(A_B_1);
      Person ab2 = (Person) cache2.getObject(A_B_2);
      assertEquals("Name for /a/b/1 is Joe", joe.getName(), ab1.getName());
      assertEquals("City for /a/b/1 is Anytown", addr1.getCity(), ab1.getAddress().getCity());
      assertEquals("Name for /a/b/1 is Jane", jane.getName(), ab2.getName());
      assertEquals("City for /a/b/1 is Anytown", addr1.getCity(), ab2.getAddress().getCity());
      assertTrue("Address for Joe and Jane is the same object", ab1.getAddress() == ab2.getAddress());

      cache1.putObject(A_C_1, bob);
      cache1.putObject(A_C_2, jill);
     
      assertNull("/a/c/1 not transferred per policy", cache2.getObject(A_C_1));

      cache2.activateRegion("/a/c");

      assertEquals("Correct name from loader for /a/b/1", joe.getName(), loader.get(A_B_1).get("name"));
      assertEquals("Correct age from loader for /a/b/1", TWENTY, loader.get(A_B_1).get("age"));
      assertEquals("Correct name from loader for /a/b/2", jane.getName(), loader.get(A_B_2).get("name"));
      assertEquals("Correct age from loader for /a/b/2", TWENTYFIVE, loader.get(A_B_2).get("age"));
      assertEquals("Correct name from loader for /a/c/1", bob.getName(), loader.get(A_C_1).get("name"));
      assertEquals("Correct age from loader for /a/c/1", FORTY, loader.get(A_C_1).get("age"));
      assertEquals("Correct name from loader for /a/c/2", jill.getName(), loader.get(A_C_2).get("name"));
      assertEquals("Correct age from loader for /a/c/2", TWENTYFIVE, loader.get(A_C_2).get("age"));
     
      Person ac1 = (Person) cache2.getObject(A_C_1);
      Person ac2 = (Person) cache2.getObject(A_C_2);
      assertEquals("Name for /a/c/1 is Bob", bob.getName(), ac1.getName());
      assertEquals("City for /a/c/1 is Fremont", addr2.getCity(), ac1.getAddress().getCity());
      assertEquals("Name for /a/c/2 is Jill", jill.getName(), ac2.getName());
      assertEquals("City for /a/c/2 is Fremont", addr2.getCity(), ac2.getAddress().getCity());
      assertTrue("Bob and Jill have same Address", ac1.getAddress() == ac2.getAddress());

      cache1.inactivateRegion("/a");

      cache1.activateRegion("/a/b/1");
      cache1.activateRegion("/a/b/2");
      cache1.activateRegion("/a/c/1");
      cache1.activateRegion("/a/c/2");

      ab1  = (Person) cache1.getObject(A_B_1);
      assertEquals("Name for /a/b/1 is Joe", joe.getName(), ab1.getName());
      assertEquals("City for /a/b/1 is Anytown", addr1.getCity(), ab1.getAddress().getCity());
      ab2 = (Person) cache1.getObject(A_B_2);;
      assertEquals("Name for /a/b/1 is Jane", jane.getName(), ab2.getName());
      assertEquals("City for /a/b/1 is Anytown", addr1.getCity(), ab2.getAddress().getCity());
      assertTrue("Address for Joe and Jane is the same object", ab1.getAddress() == ab2.getAddress());
      ac1 = (Person) cache1.getObject(A_C_1);
      assertEquals("Name for /a/c/1 is Bob", bob.getName(), ac1.getName());
      assertEquals("City for /a/c/1 is Fremont", addr2.getCity(), ac1.getAddress().getCity());
      ac2 = (Person) cache1.getObject(A_C_2);
      assertEquals("Name for /a/c/2 is Jill", jill.getName(), ac2.getName());
      assertEquals("City for /a/c/2 is Fremont", addr2.getCity(), ac2.getAddress().getCity());
      assertTrue("Address for Bob and Jill is the same object", ac1.getAddress() == ac2.getAddress());
   }
View Full Code Here

                       activators[i].getException());
           
            for (int j = 0; j < count; j++)
            {
               String fqn = "/a/b/" + names[j];
               Person p = (Person) activators[i].getCacheValue(fqn);
               assertNotNull(names[i] + ":" + fqn + " is not null", p);
               assertEquals("Correct name for " + names[i] + ":" + fqn,
                             "Person " + names[j], p.getName());
               assertEquals("Correct street for " + names[i] + ":" + fqn,
                     names[j] + " Test Street", p.getAddress().getStreet());
//               System.out.println(names[i] + ":" + fqn + " = " + activators[i].getCacheValue(fqn));
            }
           
         }
      }
View Full Code Here

TOP

Related Classes of org.jboss.cache.aop.test.Person

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.