@Test
 public void testClear() throws Exception {
   txnScheduler.runTask(
       new TestTask(
           new AbstractKernelRunnable() {
             public void run() {
               set.add(1);
               set.add(null);
               DoneRemoving.init();
               set.clear();
               assertTrue(set.isEmpty());
             }
           }),
       taskOwner);
   DoneRemoving.await(1);
   txnScheduler.runTask(
       new TestTask(
           new AbstractKernelRunnable() {
             public void run() {
               set.clear();
               assertTrue(set.isEmpty());
             }
           }),
       taskOwner);
   DoneRemoving.await(1);
 }
 @Test
 public void testClear() throws Exception {
   set.add(1);
   set.add(null);
   DoneRemoving.init();
   set.clear();
   assertTrue(set.isEmpty());
   endTransaction();
   DoneRemoving.await(1);
   startTransaction();
   set.clear();
   assertTrue(set.isEmpty());
   endTransaction();
   DoneRemoving.await(1);
 }
 @Test
 public void testContainsAll() throws Exception {
   txnScheduler.runTask(
       new TestTask(
           new AbstractKernelRunnable() {
             public void run() {
               try {
                 set.containsAll(null);
                 fail("Expected NullPointerException");
               } catch (NullPointerException e) {
               }
               Set<Object> other = new HashSet<Object>();
               assertTrue(set.containsAll(other));
               other.add(1);
               assertFalse(set.containsAll(other));
               set.add(null);
               set.add(1);
               assertTrue(set.containsAll(other));
               DoneRemoving.init();
               set.clear();
               assertFalse(set.containsAll(other));
             }
           }),
       taskOwner);
   DoneRemoving.await(1);
 }
 @SuppressWarnings("unchecked")
 @Test
 public void testIteratorCollectionNotFound() throws Exception {
   set.add(one);
   Iterator<Object> iter = set.iterator();
   dataService.setBinding("iter", new ManagedSerializable(iter));
   newTransaction();
   DoneRemoving.init();
   dataService.removeObject(set);
   endTransaction();
   DoneRemoving.await(1);
   startTransaction();
   iter = (Iterator<Object>) dataService.getBinding("iter", ManagedSerializable.class).get();
   try {
     iter.next();
     fail("Expected ObjectNotFoundException");
   } catch (ObjectNotFoundException e) {
     System.err.println(e);
   }
   try {
     iter.hasNext();
     fail("Expected ObjectNotFoundException");
   } catch (ObjectNotFoundException e) {
     System.err.println(e);
   }
   try {
     iter.remove();
     fail("Expected an exception");
   } catch (ObjectNotFoundException e) {
     System.err.println(e);
   } catch (IllegalStateException e) {
     System.err.println(e);
   }
 }
 @Test
 public void testClearObjectNotFound() throws Exception {
   txnScheduler.runTask(
       new TestTask(
           new AbstractKernelRunnable() {
             public void run() {
               set.add(one);
             }
           }),
       taskOwner);
   txnScheduler.runTask(
       new TestTask(
           new AbstractKernelRunnable() {
             public void run() {
               dataService.removeObject(one);
               DoneRemoving.init();
               set.clear();
               assertTrue(set.isEmpty());
               one = new Int(1);
               set.add(one);
             }
           }),
       taskOwner);
   DoneRemoving.await(1);
   txnScheduler.runTask(
       new TestTask(
           new AbstractKernelRunnable() {
             public void run() {
               dataService.removeObject(one);
             }
           }),
       taskOwner);
   txnScheduler.runTask(
       new TestTask(
           new AbstractKernelRunnable() {
             public void run() {
               set.clear();
               assertTrue(set.isEmpty());
             }
           }),
       taskOwner);
   DoneRemoving.await(1);
 }
 @SuppressWarnings("unchecked")
 @Test
 public void testIteratorCollectionNotFound() throws Exception {
   txnScheduler.runTask(
       new TestTask(
           new AbstractKernelRunnable() {
             public void run() {
               set.add(one);
               Iterator<Object> iter = set.iterator();
               dataService.setBinding("iter", new ManagedSerializable(iter));
             }
           }),
       taskOwner);
   txnScheduler.runTask(
       new TestTask(
           new AbstractKernelRunnable() {
             public void run() {
               DoneRemoving.init();
               dataService.removeObject(set);
             }
           }),
       taskOwner);
   DoneRemoving.await(1);
   txnScheduler.runTask(
       new TestTask(
           new AbstractKernelRunnable() {
             public void run() {
               ManagedSerializable<Iterator<Object>> msIter =
                   uncheckedCast(dataService.getBinding("iter"));
               dataService.markForUpdate(msIter);
               Iterator<Object> iter = msIter.get();
               try {
                 iter.next();
                 fail("Expected ObjectNotFoundException");
               } catch (ObjectNotFoundException e) {
                 System.err.println(e);
               }
               try {
                 iter.hasNext();
                 fail("Expected ObjectNotFoundException");
               } catch (ObjectNotFoundException e) {
                 System.err.println(e);
               }
               try {
                 iter.remove();
                 fail("Expected an exception");
               } catch (ObjectNotFoundException e) {
                 System.err.println(e);
               } catch (IllegalStateException e) {
                 System.err.println(e);
               }
             }
           }),
       taskOwner);
 }
 @Test
 public void testClearObjectNotFound() throws Exception {
   set.add(one);
   newTransaction();
   dataService.removeObject(one);
   DoneRemoving.init();
   set.clear();
   assertTrue(set.isEmpty());
   one = new Int(1);
   set.add(one);
   endTransaction();
   DoneRemoving.await(1);
   startTransaction();
   dataService.removeObject(one);
   newTransaction();
   set.clear();
   assertTrue(set.isEmpty());
   endTransaction();
   DoneRemoving.await(1);
 }
 @Test
 public void testRemoveObjectSet() throws Exception {
   DoneRemoving.init();
   dataService.removeObject(set);
   set = null;
   endTransaction();
   DoneRemoving.await(1);
   startTransaction();
   int count = getObjectCount();
   set = new ScalableHashSet<Object>();
   newTransaction();
   for (int i = 0; i < 50; i++) {
     set.add(random.nextInt());
   }
   newTransaction();
   dataService.removeObject(set);
   set = null;
   endTransaction();
   DoneRemoving.await(1);
   startTransaction();
   assertEquals(count, getObjectCount());
 }
 @Test
 public void testRemoveObjectSet() throws Exception {
   txnScheduler.runTask(
       new TestTask(
           new AbstractKernelRunnable() {
             public void run() {
               DoneRemoving.init();
               dataService.removeObject(set);
               set = null;
             }
           }),
       taskOwner);
   DoneRemoving.await(1);
   int count = getObjectCount();
   txnScheduler.runTask(
       new TestTask(
           new AbstractKernelRunnable() {
             public void run() {
               set = new ScalableHashSet<Object>();
               for (int i = 0; i < 50; i++) {
                 set.add(random.nextInt());
               }
             }
           }),
       taskOwner);
   txnScheduler.runTask(
       new TestTask(
           new AbstractKernelRunnable() {
             public void run() {
               dataService.removeObject(set);
               set = null;
             }
           }),
       taskOwner);
   DoneRemoving.await(1);
   assertEquals(count, getObjectCount());
 }
 @Test
 public void testSize() throws Exception {
   assertEquals(0, set.size());
   set.add(1);
   assertEquals(1, set.size());
   set.add(2);
   assertEquals(2, set.size());
   set.add(2);
   assertEquals(2, set.size());
   DoneRemoving.init();
   set.clear();
   assertEquals(0, set.size());
   endTransaction();
   DoneRemoving.await(1);
 }
 @Test
 public void testContainsAll() throws Exception {
   try {
     set.containsAll(null);
     fail("Expected NullPointerException");
   } catch (NullPointerException e) {
   }
   Set<Object> other = new HashSet<Object>();
   assertTrue(set.containsAll(other));
   other.add(1);
   assertFalse(set.containsAll(other));
   set.add(null);
   set.add(1);
   assertTrue(set.containsAll(other));
   DoneRemoving.init();
   set.clear();
   assertFalse(set.containsAll(other));
   endTransaction();
   DoneRemoving.await(1);
 }
 @Test
 public void testSize() throws Exception {
   txnScheduler.runTask(
       new TestTask(
           new AbstractKernelRunnable() {
             public void run() {
               assertEquals(0, set.size());
               set.add(1);
               assertEquals(1, set.size());
               set.add(2);
               assertEquals(2, set.size());
               set.add(2);
               assertEquals(2, set.size());
               DoneRemoving.init();
               set.clear();
               assertEquals(0, set.size());
             }
           }),
       taskOwner);
   DoneRemoving.await(1);
 }