Package org.hibernate.cache.jbc.access

Examples of org.hibernate.cache.jbc.access.PutFromLoadValidator$PendingPut


    protected Fqn<String> createRegionFqn(String regionName, String regionPrefix) {
        return getTypeLastRegionFqn(regionName, regionPrefix, TYPE);
    }
   
    public PutFromLoadValidator getPutFromLoadValidator() {
       return new PutFromLoadValidator(transactionManager);
    }
View Full Code Here


    protected Fqn<String> createRegionFqn(String regionName, String regionPrefix) {
        return getTypeLastRegionFqn(regionName, regionPrefix, TYPE);
    }
   
    public PutFromLoadValidator getPutFromLoadValidator() {
       return new PutFromLoadValidator(transactionManager);
    }
View Full Code Here

  public void testNakedPutTransactional() throws Exception {
    nakedPutTest(true);
  }

  private void nakedPutTest(boolean transactional) throws Exception {
    PutFromLoadValidator testee = new PutFromLoadValidator(
        transactional ? tm : null);
    if (transactional) {
      tm.begin();
    }
   
    boolean lockable = testee.acquirePutFromLoadLock(KEY1);
    try {
      assertTrue(lockable);
    }
    finally {
      if (lockable) {
        testee.releasePutFromLoadLock(KEY1);
      }
    }
  }
View Full Code Here

  public void testRegisteredPutTransactional() throws Exception {
    registeredPutTest(true);
  }

  private void registeredPutTest(boolean transactional) throws Exception {
    PutFromLoadValidator testee = new PutFromLoadValidator(
        transactional ? tm : null);
    if (transactional) {
      tm.begin();
    }
    testee.registerPendingPut(KEY1);
   
    boolean lockable = testee.acquirePutFromLoadLock(KEY1);
    try {
      assertTrue(lockable);
    }
    finally {
      if (lockable) {
        testee.releasePutFromLoadLock(KEY1);
      }
    }
  }
View Full Code Here

    nakedPutAfterRemovalTest(true, true);
  }

  private void nakedPutAfterRemovalTest(boolean transactional,
      boolean removeRegion) throws Exception {
    PutFromLoadValidator testee = new PutFromLoadValidator(
        transactional ? tm : null);
    if (removeRegion) {
      testee.invalidateRegion();
    } else {
      testee.invalidateKey(KEY1);
    }
    if (transactional) {
      tm.begin();
    }
   
    boolean lockable = testee.acquirePutFromLoadLock(KEY1);
    try {
      assertFalse(lockable);
    }
    finally {
      if (lockable) {
        testee.releasePutFromLoadLock(KEY1);
      }
    }

  }
View Full Code Here

    registeredPutAfterRemovalTest(true, true);
  }

  private void registeredPutAfterRemovalTest(boolean transactional,
      boolean removeRegion) throws Exception {
    PutFromLoadValidator testee = new PutFromLoadValidator(
        transactional ? tm : null);
    if (removeRegion) {
      testee.invalidateRegion();
    } else {
      testee.invalidateKey(KEY1);
    }
    if (transactional) {
      tm.begin();
    }
    testee.registerPendingPut(KEY1);
   
    boolean lockable = testee.acquirePutFromLoadLock(KEY1);
    try {
      assertTrue(lockable);
    }
    finally {
      if (lockable) {
        testee.releasePutFromLoadLock(KEY1);
      }
    }
  }
View Full Code Here

    registeredPutWithInterveningRemovalTest(true, true);
  }

  private void registeredPutWithInterveningRemovalTest(boolean transactional,
      boolean removeRegion) throws Exception {
    PutFromLoadValidator testee = new PutFromLoadValidator(
        transactional ? tm : null);
    if (transactional) {
      tm.begin();
    }
    testee.registerPendingPut(KEY1);
    if (removeRegion) {
      testee.invalidateRegion();
    } else {
      testee.invalidateKey(KEY1);
    }
   
    boolean lockable = testee.acquirePutFromLoadLock(KEY1);
    try {
      assertFalse(lockable);
    }
    finally {
      if (lockable) {
        testee.releasePutFromLoadLock(KEY1);
      }
    }
  }
View Full Code Here

    delayedNakedPutAfterRemovalTest(true, true);
  }

  private void delayedNakedPutAfterRemovalTest(boolean transactional,
      boolean removeRegion) throws Exception {
    PutFromLoadValidator testee = new TestValidator(transactional ? tm
        : null, 100, 1000, 500, 10000);
    if (removeRegion) {
      testee.invalidateRegion();
    } else {
      testee.invalidateKey(KEY1);
    }
    if (transactional) {
      tm.begin();
    }
    Thread.sleep(110);
   
    boolean lockable = testee.acquirePutFromLoadLock(KEY1);
    try {
      assertTrue(lockable);
    }
    finally {
      if (lockable) {
        testee.releasePutFromLoadLock(KEY1);
      }
    }

  }
View Full Code Here

  public void testMultipleRegistrationsTransactional() throws Exception {
    multipleRegistrationtest(true);
  }

  private void multipleRegistrationtest(final boolean transactional) throws Exception {
    final PutFromLoadValidator testee = new PutFromLoadValidator(transactional ? tm : null);
   
    final CountDownLatch registeredLatch = new CountDownLatch(3);
    final CountDownLatch finishedLatch = new CountDownLatch(3);
    final AtomicInteger success = new AtomicInteger();
   
    Runnable r = new Runnable() {
      public void run() {
        try {
          if (transactional) {
            tm.begin();
          }
          testee.registerPendingPut(KEY1);
          registeredLatch.countDown();
          registeredLatch.await(5, TimeUnit.SECONDS);
          if (testee.acquirePutFromLoadLock(KEY1)) {
            try {
              success.incrementAndGet();
            }
            finally {
              testee.releasePutFromLoadLock(KEY1);
            }
          }
          finishedLatch.countDown();
        }
        catch (Exception e)  {
          e.printStackTrace();
        }
      }
    };
   
    ExecutorService executor = Executors.newFixedThreadPool(3);
   
    // Start with a removal so the "isPutValid" calls will fail if
    // any of the concurrent activity isn't handled properly
   
    testee.invalidateRegion();
   
    // Do the registration + isPutValid calls
    executor.execute(r);
    executor.execute(r);
    executor.execute(r);
View Full Code Here

  public void testInvalidateRegionBlocksForInProgressPut() throws Exception {
    invalidationBlocksForInProgressPutTest(false);
  }
 
  private void invalidationBlocksForInProgressPutTest(final boolean keyOnly) throws Exception {
    final PutFromLoadValidator testee = new PutFromLoadValidator(null);
    final CountDownLatch removeLatch = new CountDownLatch(1);
    final CountDownLatch pferLatch = new CountDownLatch(1);
    final AtomicReference<Object> cache = new AtomicReference<Object>("INITIAL");
   
    Callable<Boolean> pferCallable = new Callable<Boolean>() {
        public Boolean call() throws Exception {
            testee.registerPendingPut(KEY1);
            if (testee.acquirePutFromLoadLock(KEY1)) {
              try {
                removeLatch.countDown();
                pferLatch.await();
                cache.set("PFER");
                return Boolean.TRUE;
              }
              finally {
                testee.releasePutFromLoadLock(KEY1);
              }
            }
            return Boolean.FALSE;
        }
      };
   
    Callable<Void> invalidateCallable = new Callable<Void>() {
        public Void call() throws Exception {
            removeLatch.await();
            if (keyOnly) {
              testee.invalidateKey(KEY1);
            }
            else {
              testee.invalidateRegion();
            }           
            cache.set(null);
            return null;
        }
      };
View Full Code Here

TOP

Related Classes of org.hibernate.cache.jbc.access.PutFromLoadValidator$PendingPut

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.