예제 #1
0
 @Test
 public void testAddObjectNotFound() throws Exception {
   newTransaction();
   dataService.removeObject(one);
   one = new Int(1);
   assertTrue(set.add(one));
   dataService.removeObject(one);
   newTransaction();
   assertTrue(set.add(new Int(1)));
 }
예제 #2
0
 @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);
   }
 }
예제 #3
0
 @Test
 public void testSizeObjectNotFound() throws Exception {
   set.add(one);
   newTransaction();
   dataService.removeObject(one);
   assertEquals(1, set.size());
   newTransaction();
   assertEquals(1, set.size());
 }
예제 #4
0
 @Test
 public void testIsEmptyObjectNotFound() throws Exception {
   set.add(one);
   newTransaction();
   dataService.removeObject(one);
   assertFalse(set.isEmpty());
   newTransaction();
   assertFalse(set.isEmpty());
 }
예제 #5
0
 @Test
 public void testContainsObjectNotFound() throws Exception {
   set.add(one);
   newTransaction();
   dataService.removeObject(one);
   assertFalse(set.contains(one));
   newTransaction();
   assertFalse(set.contains(one));
 }
예제 #6
0
 @Test
 public void testRemoveObjectNotFound() throws Exception {
   set.add(one);
   newTransaction();
   dataService.removeObject(one);
   one = new Int(1);
   assertFalse(set.remove(one));
   newTransaction();
   assertFalse(set.remove(one));
 }
 private void op(int i) throws Exception {
   if (random.nextInt(5) == 0) {
     DummyTransaction t = txn;
     txn = null;
     t.commit();
     long time = System.currentTimeMillis() - txnStart;
     if (time > maxTxnTime) {
       maxTxnTime = time;
       maxTxnTimeOps = txnOps;
     }
     txnStart = System.currentTimeMillis();
     txnOps = 0;
     createTxn();
   }
   txnOps++;
   int start = id * (objects + objectsBuffer);
   String name = getObjectName(start + random.nextInt(objects));
   switch (random.nextInt(whichOperations.value)) {
     case 0:
       /* Get binding */
       service.getBinding(name, Object.class);
       break;
     case 1:
       /* Set bindings */
       ModifiableObject obj = service.getBinding(name, ModifiableObject.class);
       String name2 = getObjectName(start + random.nextInt(objects));
       ModifiableObject obj2 = service.getBinding(name2, ModifiableObject.class);
       service.setBinding(name, obj2);
       service.setBinding(name2, obj);
       break;
     case 2:
       /* Modify object */
       service.getBinding(name, ModifiableObject.class).incrementNumber(service);
       break;
     case 3:
       /* Create object */
       /*
        * Get the binding first, so the new object is created with
        * proper locality.
        */
       ModifiableObject object = service.getBinding(name, ModifiableObject.class);
       service.removeObject(object);
       object = new ModifiableObject();
       service.setBinding(name, object);
       BigInteger oidBlock = service.createReference(object).getId().shiftRight(32);
       if (block == null || !block.equals(oidBlock)) {
         block = oidBlock;
         System.err.println("Thread " + id + ": create block " + block);
       }
       break;
     default:
       throw new AssertionError();
   }
 }
예제 #8
0
 @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);
 }
예제 #9
0
 /** Removes the channel server proxy and binding for the node specified during construction. */
 public void run() {
   String channelServerKey = getChannelServerKey(nodeId);
   DataService dataService = getDataService();
   try {
     dataService.removeObject(dataService.getServiceBinding(channelServerKey));
   } catch (NameNotBoundException e) {
     // already removed
     return;
   } catch (ObjectNotFoundException e) {
   }
   dataService.removeServiceBinding(channelServerKey);
 }
예제 #10
0
 @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());
 }
 /**
  * Removes the client session server proxy and binding and also removes the protocol descriptors
  * for the node specified during construction.
  */
 public void run() {
   String sessionServerKey = getClientSessionServerKey(nodeId);
   DataService dataService = getDataService();
   try {
     dataService.removeObject(dataService.getServiceBinding(sessionServerKey));
     getProtocolDescriptorsMap().remove(nodeId);
   } catch (NameNotBoundException e) {
     // already removed
     return;
   } catch (ObjectNotFoundException e) {
   }
   dataService.removeServiceBinding(sessionServerKey);
 }
예제 #12
0
 @Test
 public void testEqualsObjectNotFound() throws Exception {
   Set<Object> empty = new HashSet<Object>();
   Set<Object> containsOne = new HashSet<Object>();
   containsOne.add(one);
   set.add(one);
   newTransaction();
   dataService.removeObject(one);
   assertFalse(set.equals(empty));
   assertFalse(set.equals(containsOne));
   newTransaction();
   assertFalse(set.equals(empty));
   assertFalse(set.equals(containsOne));
 }
예제 #13
0
 @Test
 public void testCopyConstructorObjectNotFound() throws Exception {
   set.add(one);
   newTransaction();
   dataService.removeObject(one);
   try {
     new ScalableHashSet<Object>(set);
     fail("Expected ObjectNotFoundException");
   } catch (ObjectNotFoundException e) {
   }
   newTransaction();
   try {
     new ScalableHashSet<Object>(set);
     fail("Expected ObjectNotFoundException");
   } catch (ObjectNotFoundException e) {
   }
 }
예제 #14
0
 @SuppressWarnings("unchecked")
 @Test
 public void testIteratorObjectNotFound() throws Exception {
   set.add(one);
   set.add(new Int(2));
   Iterator<Object> iter = set.iterator();
   dataService.setBinding("iter", new ManagedSerializable(iter));
   newTransaction();
   dataService.removeObject(one);
   newTransaction();
   iter = (Iterator<Object>) dataService.getBinding("iter", ManagedSerializable.class).get();
   int count = 0;
   while (iter.hasNext()) {
     try {
       assertEquals(new Int(2), iter.next());
       count++;
     } catch (ObjectNotFoundException e) {
     }
   }
   assertEquals(1, count);
 }
예제 #15
0
  /**
   * Invokes the {@code disconnected} callback on this session's {@code ClientSessionListener} (if
   * present and {@code notify} is {@code true}), removes the listener and its binding (if present),
   * and then removes this session and its bindings from the specified {@code dataService}. If the
   * bindings have already been removed from the {@code dataService} this method takes no action.
   * This method should only be called within a transaction.
   *
   * @param dataService a data service
   * @param graceful {@code true} if disconnection is graceful, and {@code false} otherwise
   * @param notify {@code true} if the {@code disconnected} callback should be invoked
   * @throws TransactionException if there is a problem with the current transaction
   */
  void notifyListenerAndRemoveSession(
      final DataService dataService, final boolean graceful, boolean notify) {
    String sessionKey = getSessionKey();
    String sessionNodeKey = getSessionNodeKey();
    String listenerKey = getListenerKey();
    String eventQueueKey = getEventQueueKey();

    /*
     * Get ClientSessionListener, and remove its binding and
     * wrapper if applicable.  The listener may not be bound
     * in the data service if: the AppListener.loggedIn callback
     * either threw a non-retryable exception or returned a
     * null listener, or the application removed the
     * ClientSessionListener object from the data service.
     */
    ClientSessionListener listener = null;
    try {
      ManagedObject obj = dataService.getServiceBinding(listenerKey);
      dataService.removeServiceBinding(listenerKey);
      if (obj instanceof ListenerWrapper) {
        dataService.removeObject(obj);
        listener = ((ListenerWrapper) obj).get();
      } else {
        listener = (ClientSessionListener) obj;
      }

    } catch (NameNotBoundException e) {
      logger.logThrow(Level.FINE, e, "removing ClientSessionListener for session:{0} throws", this);
    }

    /*
     * Remove event queue and associated binding.
     */
    try {
      ManagedObject eventQueue = dataService.getServiceBinding(eventQueueKey);
      dataService.removeServiceBinding(eventQueueKey);
      dataService.removeObject(eventQueue);
    } catch (NameNotBoundException e) {
      logger.logThrow(Level.FINE, e, "removing EventQueue for session:{0} throws", this);
    }

    /*
     * Invoke listener's 'disconnected' callback if 'notify'
     * is true and a listener exists for this client session.  If the
     * 'disconnected' callback throws a non-retryable exception,
     * schedule a task to remove this session and its associated
     * bindings without invoking the listener, and rethrow the
     * exception so that the currently executing transaction aborts.
     */
    if (notify && listener != null) {
      try {
        listener.disconnected(graceful);
      } catch (RuntimeException e) {
        if (!isRetryableException(e)) {
          logger.logThrow(
              Level.WARNING,
              e,
              "invoking disconnected callback on listener:{0} " + " for session:{1} throws",
              listener,
              this);
          sessionService.scheduleTask(
              new AbstractKernelRunnable() {
                public void run() {
                  ClientSessionImpl sessionImpl = ClientSessionImpl.getSession(dataService, id);
                  sessionImpl.notifyListenerAndRemoveSession(dataService, graceful, false);
                }
              },
              identity);
        }
        throw e;
      }
    }

    /*
     * Remove this session's state and bindings.
     */
    try {
      dataService.removeServiceBinding(sessionKey);
      dataService.removeServiceBinding(sessionNodeKey);
      dataService.removeObject(this);
    } catch (NameNotBoundException e) {
      logger.logThrow(Level.WARNING, e, "session binding already removed:{0}", sessionKey);
    }

    /*
     * Remove this session's wrapper object, if it still exists.
     */
    try {
      dataService.removeObject(wrappedSessionRef.get());
    } catch (ObjectNotFoundException e) {
      // already removed
    }
  }