Example #1
0
  @Test
  public void testDescribeUserSetChanges() throws Exception {
    String changes = null;

    HttpSession httpSession = getSession();
    UserContext.newContext(getRequest(), m_user, m_customer);

    changes = DiffUtils.describeUserSetChanges(null, null, null);
    assertNull("DiffUtils.describeUserSetChanges(null, null, null) should return null", changes);

    SavedUserSet susOld = new SavedUserSet(m_customer.getCustID());
    SavedUserSet susNew = new SavedUserSet(m_customer.getCustID());

    changes = DiffUtils.describeUserSetChanges(getRequest(), susOld, susNew);
    assertNull("Expected no diffs for 2 identical user sets", changes);

    List<SearchConstraint> constraints;
    constraints = new ArrayList<SearchConstraint>();
    constraints.add(
        new SearchConstraint(
            IUserManager.PROP_USERID,
            SearchConstraintOperator.CONSTRAINT_EQUALS,
            m_user.getUserID()));

    susNew.addUsers(constraints);

    changes = DiffUtils.describeUserSetChanges(getRequest(), susOld, susNew);
    assertNotNull("Expected diffs on 2 different user sets", changes);
  }
  public void testRepeatableReadWithNull() throws Exception {
    LockTestData tl = lockTestData;
    Cache<String, String> cache = tl.cache;
    TransactionManager tm = tl.tm;

    assertNull(cache.get("k"));

    tm.begin();
    assertNull(cache.get("k"));
    Transaction reader = tm.suspend();

    tm.begin();
    cache.put("k", "v");
    assertNotNull(cache.get("k"));
    assertEquals("v", cache.get("k"));
    tm.commit();

    assertNotNull(cache.get("k"));
    assertEquals("v", cache.get("k"));

    tm.resume(reader);
    Object o = cache.get("k");
    assertNull("found value " + o, o);
    tm.commit();

    assertNotNull(cache.get("k"));
    assertEquals("v", cache.get("k"));
    assertNoLocks();
  }
  public void testSyncTxReplMap() throws Exception {
    Integer age;
    TransactionManager tm = TestingUtil.getTransactionManager(cache1);
    tm.begin();
    Transaction tx = tm.getTransaction();
    LocalListener lis = new LocalListener();

    cache1.put("age", 38);
    lis.put("name", "Ben");

    assert cache1.get("age").equals(38);
    tm.suspend();
    assertNull(
        "age on cache2 must be null as the TX has not yet been committed", cache2.get("age"));
    assertNull("age on cache1 must be null as the TX has been resumed", cache1.get("age"));
    tm.resume(tx);
    assertNotNull("age on cache1 must be not be null", cache1.get("age"));
    tm.commit();
    assertNotNull("age on cache1 must be not be null", cache1.get("age"));

    System.out.println("  ********************** ");
    // value on cache2 must be 38
    age = (Integer) cache2.get("age");
    assertNotNull("\"age\" obtained from cache2 must be non-null ", age);
    assertTrue("\"age\" must be 38", age == 38);
  }
Example #4
0
  @Test
  public void testAuthorityManagement() {
    // Try to get non-existent
    Authority authority = _userManager.getAuthority("nonexistentauthority");
    assertNull(authority);

    // Clear DB as necessary
    authority = _userManager.getAuthority("authority");
    if (authority != null) {
      _userManager.deleteAuthority(authority);
    }

    // Add
    authority = new Authority("regex");
    _userManager.addAuthority(authority);

    // Update
    authority.setRegex("newregex");
    _userManager.updateAuthority(authority);
    authority = _userManager.getAuthority("regex");
    assertNull(authority);
    authority = _userManager.getAuthority("newregex");
    assertNotNull(authority);
    assertEquals("newregex", authority.getRegex());

    // Delete
    _userManager.deleteAuthority(authority);
    authority = _userManager.getAuthority("newregex");
    assertNull(authority);
  }
  @Test
  public void testGetStudent() throws InvalidParametersException, EntityDoesNotExistException {
    int currentNumberOfStudent = studentsDb.getAllStudents().size();
    StudentAttributes s = createNewStudent();
    s.googleId = "validGoogleId";
    s.googleId = "validTeam";
    studentsDb.updateStudent(s.course, s.email, s.name, s.team, s.email, s.googleId, s.comments);

    ______TS("typical success case: existent");
    StudentAttributes retrieved = studentsDb.getStudentForEmail(s.course, s.email);
    assertNotNull(retrieved);
    assertNotNull(studentsDb.getStudentForRegistrationKey(retrieved.key));
    assertNotNull(studentsDb.getStudentForRegistrationKey(StringHelper.encrypt(retrieved.key)));
    assertNull(studentsDb.getStudentForRegistrationKey("notExistingKey"));
    ______TS("non existant student case");
    retrieved = studentsDb.getStudentForEmail("any-course-id", "*****@*****.**");
    assertNull(retrieved);

    StudentAttributes s2 = createNewStudent("*****@*****.**");
    s2.googleId = "validGoogleId2";
    studentsDb.updateStudent(
        s2.course, s2.email, s2.name, s2.team, s2.email, s2.googleId, s2.comments);
    studentsDb.deleteStudentsForGoogleId(s2.googleId);
    assertNull(studentsDb.getStudentForGoogleId(s2.course, s2.googleId));

    s2 = createNewStudent("*****@*****.**");
    assertEquals(
        true, studentsDb.getUnregisteredStudentsForCourse(s2.course).get(0).isEnrollInfoSameAs(s2));

    s2.googleId = null;
    studentsDb.updateStudent(
        s2.course, s2.email, s2.name, s2.team, s2.email, s2.googleId, s2.comments);
    assertEquals(
        true, studentsDb.getUnregisteredStudentsForCourse(s2.course).get(0).isEnrollInfoSameAs(s2));

    assertTrue(s.isEnrollInfoSameAs(studentsDb.getStudentsForGoogleId(s.googleId).get(0)));
    assertEquals(true, studentsDb.getStudentsForCourse(s.course).get(0).isEnrollInfoSameAs(s));
    assertEquals(
        true, studentsDb.getStudentsForTeam(s.team, s.course).get(0).isEnrollInfoSameAs(s));
    assertEquals(2 + currentNumberOfStudent, studentsDb.getAllStudents().size());

    ______TS("null params case");
    try {
      studentsDb.getStudentForEmail(null, "*****@*****.**");
      Assert.fail();
    } catch (AssertionError a) {
      assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, a.getMessage());
    }
    try {
      studentsDb.getStudentForEmail("any-course-id", null);
      Assert.fail();
    } catch (AssertionError a) {
      assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, a.getMessage());
    }
  }
Example #6
0
 public void testDoubleRemovalOfData2() throws Exception {
   cache.put("/foo/1/2", "item", 1);
   tm.begin();
   assertEquals(cache.get("/foo/1", "item"), null);
   cache.removeNode("/foo/1");
   assertNull(cache.get("/foo/1", "item"));
   cache.removeNode("/foo/1/2");
   assertNull(cache.get("/foo/1", "item"));
   tm.commit();
   assertFalse(cache.exists("/foo/1"));
   assertNull(cache.get("/foo/1/2", "item"));
   assertNull(cache.get("/foo/1", "item"));
 }
  /**
   * Test getMetadata API with a serial of entries. The entries have not existed in simulator/drive.
   * The test result should be null.
   *
   * <p>
   *
   * @throws KineticException if any internal error occurred.
   */
  @Test(dataProvider = "transportProtocolOptions")
  public void testGetMetadata_ReturnsNull_ForNonexistingKey(String clientName)
      throws KineticException {
    byte[] key = toByteArray("@#$%2345");
    getClient(clientName).deleteForced(key);

    assertNull(getClient(clientName).get(key));
    assertNull(getClient(clientName).getMetadata(key));

    getClient(clientName).deleteForced(key);

    logger.info(this.testEndInfo());
  }
Example #8
0
  @Test
  public void testUserGroupManagement() {
    // Try to get non-existent
    UserGroup userGroup = _userManager.getUserGroup("nonexistentusergroup");
    assertNull(userGroup);

    // Clear DB as necessary
    userGroup = _userManager.getUserGroup("testusergroup");
    if (userGroup != null) {
      _userManager.deleteUserGroup(userGroup);
    }

    // Add
    userGroup = new UserGroup();
    userGroup.setName("testusergroup");

    Authority authority = _userManager.getAuthority("testauthority");
    if (authority == null) {
      authority = new Authority("testauthority");
      _userManager.addAuthority(authority);
    }
    userGroup.getAuthorities().add(authority);

    User user = _userManager.getUser("testuser");
    if (user == null) {
      user = getTestUser();
      _userManager.addUser(user);
    }

    _userManager.addUserGroup(userGroup);

    // Update
    Authority additionalAuthority = _userManager.getAuthority("additionalauthority");
    if (additionalAuthority == null) {
      additionalAuthority = new Authority("additionalauthority");
      _userManager.addAuthority(additionalAuthority);
    }
    userGroup.getAuthorities().add(additionalAuthority);
    _userManager.updateUserGroup(userGroup);
    userGroup = _userManager.getUserGroup("testusergroup");
    assertNotNull(userGroup);
    assertTrue(userGroup.getAuthorities().contains(additionalAuthority));

    // Delete
    _userManager.deleteUserGroup(userGroup);
    userGroup = _userManager.getUserGroup("testusergroup");
    assertNull(userGroup);
  }
  @Test
  public void testStop() throws Exception {
    RoundRobinSchedulerStats stats =
        EasyMock.createMockBuilder(RoundRobinSchedulerStats.class)
            .withConstructor()
            .addMockedMethod("unregisterMBean")
            .createStrictMock();

    MovingAverage mavg = EasyMock.createStrictMock(MovingAverage.class);
    stats.m_addMavg = mavg;
    stats.m_addMavg.stopTimer();
    EasyMock.expectLastCall();
    stats.unregisterMBean();
    EasyMock.expectLastCall();

    EasyMock.replay(stats, mavg);
    stats.stop();
    EasyMock.verify(stats, mavg);
    assertNull("Mavg should be null.", stats.m_addMavg);

    // with no avg
    EasyMock.reset(stats);
    EasyMock.replay(stats);
    stats.stop();
    EasyMock.verify(stats);
  }
 @Test
 public void invalidSecurity() throws Exception {
   ExternalIdBundle invalidKey =
       ExternalIdBundle.of(ExternalSchemes.bloombergTickerSecurityId("INVALID"));
   Security sec = _securityProvider.getSecurity(invalidKey);
   assertNull(sec);
 }
  @Test
  public final void testDeleteWithPropertiesButParentPreserved() {
    final IExternalDataDAO externalDataDAO = daoFactory.getExternalDataDAO();
    final ExternalDataPE deletedData = findExternalData(CHILD_CODE);

    // Deleted data set should have all collections which prevent it from deletion empty.
    assertTrue(deletedData.getChildren().isEmpty());

    // delete
    externalDataDAO.delete(deletedData);

    // test successful deletion of data set
    assertNull(externalDataDAO.tryGetByTechId(TechId.create(deletedData)));

    // test successful deletion of data set properties
    assertFalse(deletedData.getProperties().isEmpty());
    List<EntityTypePropertyTypePE> retrievedPropertyTypes =
        daoFactory
            .getEntityPropertyTypeDAO(EntityKind.DATA_SET)
            .listEntityPropertyTypes(deletedData.getEntityType());
    for (DataSetPropertyPE property : deletedData.getProperties()) {
      int index = retrievedPropertyTypes.indexOf(property.getEntityTypePropertyType());
      EntityTypePropertyTypePE retrievedPropertyType = retrievedPropertyTypes.get(index);
      assertFalse(retrievedPropertyType.getPropertyValues().contains(property));
    }

    // deleted sample had parent connected that should not have been deleted
    // NOTE: somehow cannot get parents even though connection is the same as with children
    // DataPE parent = deletedData.tryGetParent();
    // assertNotNull(parent);
    // assertNotNull(externalDataDAO.tryGetByTechId(new TechId(HibernateUtils.getId(parent))));
    findExternalData(PARENT_CODE);
  }
  public void testStateTransfer() throws Exception {
    // Insert initial data in the cache
    Set<Object> keys = new HashSet<Object>();
    for (int i = 0; i < NUM_KEYS; i++) {
      Object key = "key" + i;
      keys.add(key);
      cache(0).put(key, key);
    }

    log.trace("State transfer happens here");
    // add a third node
    addClusterEnabledCacheManager(dccc);
    waitForClusterToForm();

    log.trace("Checking the values from caches...");
    int keysOnJoiner = 0;
    for (Object key : keys) {
      log.tracef("Checking key: %s", key);
      // check them directly in data container
      InternalCacheEntry d0 = advancedCache(0).getDataContainer().get(key);
      InternalCacheEntry d1 = advancedCache(1).getDataContainer().get(key);
      InternalCacheEntry d2 = advancedCache(2).getDataContainer().get(key);
      assertEquals(key, d0.getValue());
      assertNull(d1);
      if (d2 != null) {
        keysOnJoiner++;
      }
    }

    assertTrue("The joiner should receive at least one key", keysOnJoiner > 0);
  }
Example #13
0
  public void testGetCourse() throws Exception {

    ______TS("failure: course doesn't exist");

    assertNull(coursesLogic.getCourse("nonexistant-course"));

    ______TS("success: typical case");

    CourseAttributes c = new CourseAttributes();
    c.id = "Computing101-getthis";
    c.name = "Basic Computing Getting";
    coursesDb.createEntity(c);

    assertEquals(c.id, coursesLogic.getCourse(c.id).id);
    assertEquals(c.name, coursesLogic.getCourse(c.id).name);

    coursesDb.deleteEntity(c);
    ______TS("Null parameter");

    try {
      coursesLogic.getCourse(null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }
  @Test
  public void testAddDeleteObject() throws Exception {
    TestUtil.displayTestTile(this, "testDeleteObject");

    OperationResult result = new OperationResult(this.getClass().getName() + ".testDelete");

    Collection<ResourceAttribute<?>> identifiers = addSampleResourceObject("john", "John", "Smith");

    String uid = null;
    for (ResourceAttribute<?> resourceAttribute : identifiers) {
      if (ConnectorFactoryIcfImpl.ICFS_UID.equals(resourceAttribute.getElementName())) {
        uid = resourceAttribute.getValue(String.class).getValue();
        System.out.println("uuuuid:" + uid);
        assertNotNull(uid);
      }
    }

    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);

    cc.deleteObject(accountDefinition, null, identifiers, result);

    PrismObject<ShadowType> resObj = null;
    try {
      resObj = cc.fetchObject(ShadowType.class, accountDefinition, identifiers, null, result);
      Assert.fail();
    } catch (ObjectNotFoundException ex) {
      AssertJUnit.assertNull(resObj);
    }
  }
 @Test
 public void lookupUnbound() throws Exception {
   registry.bind(KEY, VALUE);
   registry.unbind(KEY);
   final String result = registry.lookup(KEY);
   assertNull("Expectected value not to be bound", result);
 }
  /**
   * WARNING: don't do stupid things such like below, we do this because we can guarantee the shard
   * id will NOT change. if you want to use cobar client corretly, make sure you are partitioning
   * you databases with shard id that will not be changed once it's created!!!
   */
  public void testUpdateOnCobarSqlMapClientTemplate() {
    String[] names = {"Aaron", "Amily", "Aragon", "Darren", "Darwin"};
    batchInsertMultipleFollowersAsFixture(names);

    String nameSuffix = "Wang";
    for (String name : names) {
      Follower follower =
          (Follower)
              getSqlMapClientTemplate()
                  .queryForObject("com.alibaba.cobar.client.entities.Follower.finaByName", name);
      assertNotNull(follower);
      follower.setName(follower.getName() + nameSuffix);
      getSqlMapClientTemplate()
          .update("com.alibaba.cobar.client.entities.Follower.update", follower);

      Long id = follower.getId();

      follower = null;
      follower =
          (Follower)
              getSqlMapClientTemplate()
                  .queryForObject("com.alibaba.cobar.client.entities.Follower.finaByName", name);
      assertNull(follower);

      follower =
          (Follower)
              getSqlMapClientTemplate()
                  .queryForObject("com.alibaba.cobar.client.entities.Follower.load", id);
      assertNotNull(follower);
      assertEquals(name + nameSuffix, follower.getName());
    }
  }
  public void testEventFilter() throws Exception {
    Object[] filterFactoryParams = new Object[] {"string_key_1", "user_1"};
    ClientEntryListener listener = new ClientEntryListener();
    remoteCache.addClientListener(listener, filterFactoryParams, null);

    User user1 = new UserPB();
    user1.setId(1);
    user1.setName("John");
    user1.setSurname("Doe");
    user1.setGender(User.Gender.MALE);
    user1.setAge(22);

    remoteCache.put("string_key_1", "string value 1");
    remoteCache.put("string_key_2", "string value 2");
    remoteCache.put("user_1", user1);

    assertEquals(3, remoteCache.keySet().size());

    ClientCacheEntryCreatedEvent e = listener.createEvents.poll(5, TimeUnit.SECONDS);
    assertEquals("string_key_1", e.getKey());

    e = listener.createEvents.poll(5, TimeUnit.SECONDS);
    assertEquals("user_1", e.getKey());

    e = listener.createEvents.poll(5, TimeUnit.SECONDS);
    assertNull("No more elements expected in queue!", e);
  }
  @Test
  public void test100AddDeleteObject() throws Exception {
    final String TEST_NAME = "test100AddDeleteObject";
    TestUtil.displayTestTile(this, TEST_NAME);

    OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME);

    Collection<ResourceAttribute<?>> identifiers = addSampleResourceObject("john", "John", "Smith");

    String uid = null;
    for (ResourceAttribute<?> resourceAttribute : identifiers) {
      if (ConnectorFactoryIcfImpl.ICFS_UID.equals(resourceAttribute.getElementName())) {
        uid = resourceAttribute.getValue(String.class).getValue();
        System.out.println("uuuuid:" + uid);
        assertNotNull(uid);
      }
    }

    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(
            ProvisioningTestUtil.OBJECT_CLASS_INETORGPERSON_NAME);

    cc.deleteObject(accountDefinition, null, identifiers, result);

    ResourceObjectIdentification identification =
        new ResourceObjectIdentification(accountDefinition, identifiers);
    PrismObject<ShadowType> resObj = null;
    try {
      resObj = cc.fetchObject(ShadowType.class, identification, null, result);
      Assert.fail();
    } catch (ObjectNotFoundException ex) {
      AssertJUnit.assertNull(resObj);
    }
  }
  @Test
  public void test110ChangeModifyObject() throws Exception {
    final String TEST_NAME = "test110ChangeModifyObject";
    TestUtil.displayTestTile(this, TEST_NAME);

    OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME);

    Collection<ResourceAttribute<?>> identifiers = addSampleResourceObject("john", "John", "Smith");

    Set<Operation> changes = new HashSet<Operation>();

    changes.add(createAddAttributeChange("employeeNumber", "123123123"));
    changes.add(createReplaceAttributeChange("sn", "Smith007"));
    changes.add(createAddAttributeChange("street", "Wall Street"));
    changes.add(createDeleteAttributeChange("givenName", "John"));

    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(
            ProvisioningTestUtil.OBJECT_CLASS_INETORGPERSON_NAME);

    cc.modifyObject(accountDefinition, identifiers, changes, result);

    ResourceObjectIdentification identification =
        new ResourceObjectIdentification(accountDefinition, identifiers);
    PrismObject<ShadowType> shadow = cc.fetchObject(ShadowType.class, identification, null, result);
    ResourceAttributeContainer resObj = ShadowUtil.getAttributesContainer(shadow);

    AssertJUnit.assertNull(
        resObj.findAttribute(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "givenName")));

    String addedEmployeeNumber =
        resObj
            .findAttribute(
                new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "employeeNumber"))
            .getValue(String.class)
            .getValue();
    String changedSn =
        resObj
            .findAttribute(new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "sn"))
            .getValues(String.class)
            .iterator()
            .next()
            .getValue();
    String addedStreet =
        resObj
            .findAttribute(new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "street"))
            .getValues(String.class)
            .iterator()
            .next()
            .getValue();

    System.out.println("changed employee number: " + addedEmployeeNumber);
    System.out.println("changed sn: " + changedSn);
    System.out.println("added street: " + addedStreet);

    AssertJUnit.assertEquals("123123123", addedEmployeeNumber);
    AssertJUnit.assertEquals("Smith007", changedSn);
    AssertJUnit.assertEquals("Wall Street", addedStreet);
  }
Example #20
0
  @Test
  public void testDescribeReviewerGroupReviewerChanges() throws Exception {
    String changes = null;

    UserContext.newContext(getRequest(), m_user, m_customer);

    changes = DiffUtils.describeReviewerGroupReviewerChanges(null, null, null);
    assertNull(
        "DiffUtils.describeReviewerGroupReviewerChanges(null, null, null) should return null",
        changes);

    List<SearchConstraint> constraints;
    constraints = new ArrayList<SearchConstraint>();
    constraints.add(
        new SearchConstraint(
            IUserManager.PROP_USERID,
            SearchConstraintOperator.CONSTRAINT_EQUALS,
            m_user.getUserID()));

    SavedUserSet reviewers = new SavedUserSet(m_customer.getCustID());
    reviewers.addUsers(constraints);

    ReviewerGroup oldRG =
        new ReviewerGroup(m_customer.getCustID(), 1, "name", reviewers, null, "extra");
    ReviewerGroup newRG =
        new ReviewerGroup(m_customer.getCustID(), 1, "name", reviewers, null, "extra");

    changes = DiffUtils.describeReviewerGroupReviewerChanges(getRequest(), oldRG, newRG);
    assertNull("Expected no diffs for 2 identical user sets", changes);

    reviewers = new SavedUserSet(m_customer.getCustID());
    newRG.setReviewers(reviewers);

    changes = DiffUtils.describeReviewerGroupReviewerChanges(getRequest(), oldRG, newRG);
    assertNotNull("Expected diffs on 2 different reviewer groups", changes);

    SavedUserSet reviewers1 = new SavedUserSet(m_customer.getCustID());
    reviewers1.addConstraintSets(InternalUserSets.getAllUsersSet(m_customer.getCustID()));
    oldRG.setReviewers(reviewers1);

    SavedUserSet reviewers2 = new SavedUserSet(m_customer.getCustID());
    newRG.setReviewers(reviewers2);

    changes = DiffUtils.describeReviewerGroupReviewerChanges(getRequest(), oldRG, newRG);
    assertNotNull("Expected diffs on 2 different reviewer groups", changes);
  }
 @Override
 public void writeArrayRecord(Object[] array) {
   for (int i = 0; i < array.length; i++) {
     // primary key cant be null
     if (i > 0) {
       assertNull(array[i]);
     }
   }
 }
 @Test
 public void SingleNonMatchingProperty() {
   final MockPropertyPreservingFunction func = getFunction();
   final List<ValueSpecification> specses =
       getSpecs(
           ValueProperties.builder().with("A", "V").get(),
           ValueProperties.builder().with("A", "X").get());
   assertNull(func.getResultProperties(specses));
 }
  private void doWritingCacheTest(String cacheName, boolean tx) throws InterruptedException {
    // Start the first cache
    final EmbeddedCacheManager manager1 = createCacheManager();
    Cache<Object, Object> cache1 = manager1.getCache(cacheName);

    TestingUtil.replaceComponent(
        manager1, ClusterTopologyManager.class, new DelayingClusterTopologyManager(manager1), true);

    // Start the second cache
    EmbeddedCacheManager manager2 = createCacheManager();
    manager2.getCache(cacheName);

    writeInitialData(cache1);

    WritingThread writerThread = new WritingThread(cache1, tx);
    writerThread.start();

    manager2.stop();

    // Pause for view to update
    TestingUtil.blockUntilViewsReceived(60000, false, cache1);
    TestingUtil.waitForRehashToComplete(cache1);

    EmbeddedCacheManager manager3 = createCacheManager();
    Cache<Object, Object> cache3 = manager3.getCache(cacheName);

    // Pause to give caches time to see each other
    TestingUtil.blockUntilViewsReceived(60000, cache1, cache3);
    TestingUtil.waitForRehashToComplete(cache1, cache3);

    writerThread.stopThread();
    writerThread.join(60000);

    verifyInitialData(cache3);

    int count = writerThread.result();

    // Wait for the replication queue to be emptied
    final ReplicationQueue replQueue1 =
        cache1.getAdvancedCache().getComponentRegistry().getComponent(ReplicationQueue.class);
    eventually(
        new Condition() {
          @Override
          public boolean isSatisfied() throws Exception {
            return replQueue1.getElementsCount() == 0;
          }
        });

    // Wait a little longer, even the replication queue sends the commands asynchronously
    Thread.sleep(1000);

    for (int c = 0; c < count; c++) {
      Object o = cache3.get("test" + c);
      // Nothing should be left after a put/remove on a key
      assertNull(o);
    }
  }
  @Test
  public void testRegisterMBean() throws Exception {
    RoundRobinSchedulerStats stats =
        EasyMock.createMockBuilder(RoundRobinSchedulerStats.class)
            .withConstructor()
            .addMockedMethod("getMBeanServer")
            .addMockedMethod("createObjectName")
            .createStrictMock();

    // do nothing
    stats.setUseJMX(false);
    EasyMock.replay(stats);
    stats.registerMBean();
    EasyMock.verify(stats);
    assertNull("Object name should still be null.", stats.m_mbeanName);

    // now work
    EasyMock.reset(stats);
    stats.setUseJMX(true);
    MBeanServer mbs = EasyMock.createStrictMock(MBeanServer.class);
    ObjectName objectName = EasyMock.createStrictMock(ObjectName.class);
    EasyMock.expect(stats.getMBeanServer()).andReturn(mbs);
    EasyMock.expect(stats.createObjectName()).andReturn(objectName);
    EasyMock.expect(mbs.registerMBean(stats, objectName)).andReturn(null);

    EasyMock.replay(stats, mbs, objectName);
    stats.registerMBean();
    EasyMock.verify(stats, mbs, objectName);
    assertEquals("Object name should not be null.", objectName, stats.m_mbeanName);

    // with exception that is just logged
    EasyMock.reset(stats, mbs, objectName);
    stats.m_mbeanName = null;
    EasyMock.expect(stats.getMBeanServer()).andReturn(mbs);
    EasyMock.expect(stats.createObjectName()).andReturn(objectName);
    EasyMock.expect(mbs.registerMBean(stats, objectName))
        .andThrow(new NotCompliantMBeanException("blah"));

    EasyMock.replay(stats, mbs, objectName);
    stats.registerMBean();
    EasyMock.verify(stats, mbs, objectName);
    assertNull("Object name should still be null.", stats.m_mbeanName);
  }
  /**
   * Test getNext API with the last entry existed in simulator/drive. The test result should be
   * null.
   *
   * <p>
   *
   * @throws KineticException if any internal error occurred.
   */
  @Test(dataProvider = "transportProtocolOptions")
  public void testGetNext_ReturnsNull_IfLastValue(String clientName) throws KineticException {
    byte[] key = toByteArray("key");
    cleanNextData(key, getClient(clientName));
    getClient(clientName).putForced(new Entry(key, toByteArray("value")));
    assertNull(getClient(clientName).getNext(key));

    getClient(clientName).deleteForced(key);
    logger.info(this.testEndInfo());
  }
  @Test
  public void convertTransientValue() throws AttributeNotFoundException {
    TransientValueBean bean = new TransientValueBean();
    bean.value = "value";
    bean.transientValue = "transient";

    Map ret = (Map) converter.convertToJson(bean, null, JsonConvertOptions.DEFAULT);
    assertNull(ret.get("transientValue"));
    assertEquals(ret.get("value"), "value");
  }
 /** Tests that fields are set correctly and that fields that should be null are. */
 @Test
 public void test() {
   assertEquals(NAME, INDEX_NO_DESCRIPTION.getName());
   assertEquals(NAME, INDEX_WITH_DESCRIPTION.getName());
   assertNull(INDEX_NO_DESCRIPTION.getDescription());
   assertEquals(DESCRIPTION, INDEX_WITH_DESCRIPTION.getDescription());
   assertEquals(COMPONENTS, INDEX_NO_DESCRIPTION.getEquityComponents());
   assertEquals(COMPONENTS, INDEX_WITH_DESCRIPTION.getEquityComponents());
   assertEquals(WEIGHTING_TYPE, INDEX_NO_DESCRIPTION.getWeightingType());
   assertEquals(WEIGHTING_TYPE, INDEX_WITH_DESCRIPTION.getWeightingType());
 }
  public void testRepeatableReadWithNullRemoval() throws Exception {
    LockTestData tl = lockTestData;
    Cache<String, String> cache = tl.cache;
    TransactionManager tm = tl.tm;

    // start with an empty cache
    tm.begin();
    cache.get("a");
    Transaction tx = tm.suspend();

    cache.put("a", "v2");
    assertEquals(cache.get("a"), "v2");

    tm.resume(tx);
    assertNull("expected null but received " + cache.get("a"), cache.get("a"));
    cache.remove("a");
    tm.commit();

    assertNull("expected null but received " + cache.get("a"), cache.get("a"));
  }
  public void testRemoveFailure() {
    failureInterceptor.disable();
    cache("LON", 0).put("k", "v");
    assertEquals("v", cache("LON", 1).get("k"));
    assertEquals("v", backup("LON").get("k"));

    failureInterceptor.enable();
    try {
      cache("LON", 0).remove("k");
      checkFailOnBackupFailure();
    } catch (CacheException e) {
      checkNonFailOnBackupFailure();
    }

    assertNull(cache("LON", 0).get("k"));
    assertNull(cache("LON", 1).get("k"));

    assertTrue(failureInterceptor.removeFailed);
    assertEquals("v", backup("LON").get("k"));
  }
  @Test
  public void testConstructor() throws Exception {
    RoundRobinSchedulerStats stats = new RoundRobinSchedulerStats();
    assertFalse("JMX should not be enabled by default.", stats.isUseJMX());

    stats.setUseJMX(true);
    assertTrue("JMX should be enabled.", stats.isUseJMX());
    assertEquals("Wrong default mavg period.", 300000, stats.getAddMavgPeriod());
    assertNull("Mavg should not be created.", stats.m_addMavg);
    assertEquals("Wrong default mavg sample size.", 360, stats.getAddMavgSampleSize());
  }