コード例 #1
0
  public void testValidations() throws Exception {
    // Valid object ids
    ObjectIDSet validOids = new BitSetObjectIDSet();
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 50; j++) {
        long longOid = 100 * i + j;
        validOids.add(new ObjectID(longOid));
      }
    }

    ClientID[] cids = new ClientID[10];
    for (int i = 0; i < 10; i++) {
      cids[i] = new ClientID(i);
    }

    for (int i = 0; i < 10; i++) {
      ObjectIDSet validate = new BitSetObjectIDSet();
      for (int j = 0; j < 100; j++) {
        long longOid = 100 * i + j;
        validate.add(new ObjectID(longOid));
      }
      invalidateObjectManager.addObjectsToValidateFor(cids[i], validate);
    }

    invalidateObjectManager.start();

    invalidateObjectManager.validateObjects(validOids);

    ArrayList list = inValidateSink.getList();
    Assert.assertEquals(10, list.size());

    for (int i = 0; i < 10; i++) {
      InvalidateObjectsForClientContext clientContext =
          (InvalidateObjectsForClientContext) list.get(i);
      ClientID cid = clientContext.getClientID();
      int k = (int) cid.toLong();

      Invalidations invalidationsGot = invalidateObjectManager.getObjectsIDsToInvalidate(cid);
      Invalidations expected = new Invalidations();
      ObjectID mapID = ObjectID.NULL_ID;
      for (int j = 50; j < 100; j++) {
        long longOid = 100 * k + j;
        expected.add(mapID, new ObjectID(longOid));
      }
      Assert.assertEquals(expected, invalidationsGot);
    }
  }
コード例 #2
0
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   invalidateObjectManager =
       new InvalidateObjectManagerImpl(Mockito.mock(ServerTransactionManager.class));
   validateSink = new TestSinkAdaptor();
   inValidateSink = new TestSinkAdaptor();
   configurationContext = new TestConfigurationContext();
   invalidateObjectManager.initializeContext(configurationContext);
 }
コード例 #3
0
  public void testBasic() throws Exception {
    invalidateObjectManager.start();

    ClientID cid1 = new ClientID(1);
    ClientID cid2 = new ClientID(2);

    ObjectID mapId1 = new ObjectID(1001);
    ObjectID mapId2 = new ObjectID(1002);
    ObjectID mapId3 = new ObjectID(1003);

    Invalidations invalidations = new Invalidations();
    for (int i = 1; i <= 10; i++) {
      invalidations.add(mapId1, new ObjectID(i));
      invalidations.add(mapId2, new ObjectID(i + 10));
    }

    invalidateObjectManager.invalidateObjectFor(cid1, invalidations);

    Invalidations invalidationsGot = invalidateObjectManager.getObjectsIDsToInvalidate(cid1);
    Assert.assertTrue(invalidationsGot.equals(invalidations));
    ArrayList list = inValidateSink.getList();
    Assert.assertEquals(1, list.size());
    InvalidateObjectsForClientContext clientContext =
        (InvalidateObjectsForClientContext) list.get(0);
    Assert.assertEquals(cid1, clientContext.getClientID());
    list.clear();

    invalidations = new Invalidations();
    for (int i = 1; i <= 10; i++) {
      invalidations.add(mapId1, new ObjectID(i));
      invalidations.add(mapId2, new ObjectID(i + 10));
    }
    Invalidations total = new Invalidations();
    total.add(invalidations);

    list = inValidateSink.getList();
    Assert.assertEquals(0, list.size());
    invalidateObjectManager.invalidateObjectFor(cid1, invalidations);
    list = inValidateSink.getList();
    Assert.assertEquals(1, list.size());

    Invalidations invalidations2 = new Invalidations();
    for (int i = 1; i <= 10; i++) {
      invalidations2.add(mapId3, new ObjectID(i + 20));
    }
    total.add(invalidations2);

    invalidateObjectManager.invalidateObjectFor(cid1, invalidations2);
    list = inValidateSink.getList();
    Assert.assertEquals(1, list.size());

    invalidationsGot = invalidateObjectManager.getObjectsIDsToInvalidate(cid1);
    Assert.assertTrue(invalidationsGot.equals(total));

    list.clear();

    invalidationsGot = invalidateObjectManager.getObjectsIDsToInvalidate(cid1);
    Assert.assertNull(invalidationsGot);

    Invalidations invalidationsCid1 = new Invalidations();
    Invalidations invalidationsCheckCid1 = new Invalidations();
    Invalidations invalidationsCid2 = new Invalidations();
    Invalidations invalidationsCheckCid2 = new Invalidations();
    for (int i = 1; i <= 10; i++) {
      invalidationsCid1.add(mapId1, new ObjectID(i));
      invalidationsCheckCid1.add(mapId1, new ObjectID(i));
      invalidationsCid2.add(mapId2, new ObjectID(i + 10));
      invalidationsCheckCid2.add(mapId2, new ObjectID(i + 10));
    }

    invalidateObjectManager.invalidateObjectFor(cid1, invalidationsCid1);
    invalidateObjectManager.invalidateObjectFor(cid2, invalidationsCid2);

    list = inValidateSink.getList();
    Assert.assertEquals(2, list.size());
    clientContext = (InvalidateObjectsForClientContext) list.get(0);
    Assert.assertEquals(cid1, clientContext.getClientID());
    clientContext = (InvalidateObjectsForClientContext) list.get(1);
    Assert.assertEquals(cid2, clientContext.getClientID());

    invalidationsGot = invalidateObjectManager.getObjectsIDsToInvalidate(cid1);
    Assert.assertTrue(invalidationsGot.equals(invalidationsCheckCid1));

    invalidationsGot = invalidateObjectManager.getObjectsIDsToInvalidate(cid2);
    Assert.assertTrue(invalidationsGot.equals(invalidationsCheckCid2));
  }