Search in sources :

Example 46 with EventID

use of org.apache.geode.internal.cache.EventID in project geode by apache.

the class HARQAddOperationJUnitTest method testQueueAddOperationWithoutConflation.

/**
   * Add operation without conflation : 1) Region should have an entry containing counter vs
   * Conflatable object. 2) Events Map should have size as 1 with one ThreadIdentifer objecta s key
   * & Last DispatchedWrapper as value. 3) This wrapper should have a set with size 1. 4) The
   * available IDs set shoudl have size 1. 5) Put another object by same thread. 6) The wrapper set
   * & availableIs List should have size 2 .
   */
@Test
public void testQueueAddOperationWithoutConflation() throws Exception {
    this.logWriter.info("HARegionQueueJUnitTest : testQueueAddOperationWithoutConflation BEGIN");
    this.rq = createHARegionQueue("testQueueAddOperationWithConflation");
    EventID id1 = new EventID(new byte[] { 1 }, 1, 1);
    EventID id2 = new EventID(new byte[] { 1 }, 1, 2);
    ConflatableObject c1 = new ConflatableObject(KEY1, VALUE1, id1, false, "region1");
    ConflatableObject c2 = new ConflatableObject(KEY2, VALUE2, id2, false, "region1");
    this.rq.put(c1);
    assertNull(rq.getConflationMapForTesting().get("region1"));
    assertEquals(1, rq.getAvalaibleIds().size());
    assertEquals(1, rq.getCurrentCounterSet(id1).size());
    this.rq.put(c2);
    assertNull(rq.getConflationMapForTesting().get("region1"));
    assertEquals(2, rq.getAvalaibleIds().size());
    assertEquals(2, rq.getCurrentCounterSet(id1).size());
    Iterator iter = rq.getCurrentCounterSet(id1).iterator();
    if (iter.hasNext()) {
        Long cntr = (Long) iter.next();
        ConflatableObject co = (ConflatableObject) this.rq.getRegion().get(cntr);
        assertEquals(KEY1, co.getKeyToConflate());
        assertEquals(VALUE1, co.getValueToConflate());
    }
    if (iter.hasNext()) {
        Long cntr = (Long) iter.next();
        ConflatableObject co = (ConflatableObject) this.rq.getRegion().get(cntr);
        assertEquals(KEY2, co.getKeyToConflate());
        assertEquals(VALUE2, co.getValueToConflate());
    }
    this.logWriter.info("HARegionQueueJUnitTest : testQueueAddOperationWithoutConflation END");
}
Also used : Iterator(java.util.Iterator) EventID(org.apache.geode.internal.cache.EventID) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 47 with EventID

use of org.apache.geode.internal.cache.EventID in project geode by apache.

the class HARQAddOperationJUnitTest method testQueueAddOperationWithConflation.

/**
   * Add operation with conflation : 1) Add Key1 Val1 & then Key1 Val2. 2) At the end of second
   * operation , Region should contain the entry correspodning to value 2 3) Available IDs , Last
   * DispatchedWrapper Set & Conflation Map should have size 1. 4) Conflation Map ,
   * LastDispatchedWrapper Set & Available IDs should have counter corresponding to second operation
   */
@Test
public void testQueueAddOperationWithConflation() throws Exception {
    this.logWriter.info("HARegionQueueJUnitTest : testQueueAddOperationWithConflation BEGIN");
    this.rq = createHARegionQueue("testQueueAddOperationWithConflation");
    EventID id1 = new EventID(new byte[] { 1 }, 1, 1);
    EventID id2 = new EventID(new byte[] { 1 }, 1, 2);
    ConflatableObject c1 = new ConflatableObject(KEY1, VALUE1, id1, true, "region1");
    ConflatableObject c2 = new ConflatableObject(KEY1, VALUE2, id2, true, "region1");
    this.rq.put(c1);
    this.rq.put(c2);
    Map conflationMap = (Map) rq.getConflationMapForTesting().get("region1");
    assertEquals(1, conflationMap.size());
    Long cntr = (Long) conflationMap.get(KEY1);
    ConflatableObject retValue = (ConflatableObject) rq.getRegion().get(cntr);
    assertEquals(VALUE2, retValue.getValueToConflate());
    assertEquals(1, rq.getAvalaibleIds().size());
    assertEquals(1, rq.getCurrentCounterSet(id1).size());
    this.logWriter.info("HARegionQueueJUnitTest : testQueueAddOperationWithConflation END");
}
Also used : EventID(org.apache.geode.internal.cache.EventID) Map(java.util.Map) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 48 with EventID

use of org.apache.geode.internal.cache.EventID in project geode by apache.

the class HARQAddOperationJUnitTest method testNoExpiryOnThreadIdentifier.

/**
   * Add operation which creates the LastDispatchedAndCurrentEvents object should also add it to the
   * Region with Threaddentifer as key & sequence as the value for Expiry. Validate that expiry on
   * ThreadIdentifier does not removes itself from Events Map as data is lying & it resets the self
   * expiry. Validate the data present in Queue experiences expiry. After the expiry of the data ,
   * AvaialbleIds size should be 0, entry removed from Region, LastDispatchedWrapperSet should have
   * size 0.
   */
@Test
public void testNoExpiryOnThreadIdentifier() {
    try {
        HARegionQueueAttributes hqa = new HARegionQueueAttributes();
        hqa.setExpiryTime(8);
        HARegionQueue regionqueue = createHARegionQueue("testing", hqa);
        EventID id1 = new EventID(new byte[] { 1 }, 1, 1);
        EventID id2 = new EventID(new byte[] { 1 }, 1, 2);
        ConflatableObject c1 = new ConflatableObject(KEY1, VALUE1, id1, true, "region1");
        ConflatableObject c2 = new ConflatableObject(KEY1, VALUE2, id2, true, "region1");
        ThreadIdentifier threadId = new ThreadIdentifier(c1.getEventId().getMembershipID(), c1.getEventId().getThreadID());
        regionqueue.put(c1);
        Object o = regionqueue.take();
        assertNotNull(o);
        // wait for some time and put second object
        Thread.sleep(3000);
        regionqueue.put(c2);
        // wait for some more time so that C2 has not expired
        Thread.sleep(4000);
        Map eventsMap = regionqueue.getEventsMapForTesting();
        // verify that ThreadIdentifier does not remove itself as data is
        // lying
        assertNotNull("ThreadIdentifier removed itself through expiry even though data was lying in the queue", eventsMap.get(threadId));
        // wait for some more time to allow expiry on data
        Thread.sleep(16000);
        // After the expiry of the data , AvaialbleIds size should be 0,
        // entry
        // removed from Region, LastDispatchedWrapperSet should have size 0.
        assertEquals(0, regionqueue.getRegion().entrySet(false).size());
        assertEquals(0, regionqueue.getAvalaibleIds().size());
        assertNull(regionqueue.getCurrentCounterSet(id1));
    } catch (Exception e) {
        e.printStackTrace();
        fail(" test failed due to " + e);
    }
}
Also used : EventID(org.apache.geode.internal.cache.EventID) Map(java.util.Map) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 49 with EventID

use of org.apache.geode.internal.cache.EventID in project geode by apache.

the class ClearPropagationDUnitTest method acquireConnectionsAndClear.

public static void acquireConnectionsAndClear(String host) {
    try {
        Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
        assertNotNull(r1);
        String poolName = r1.getAttributes().getPoolName();
        assertNotNull(poolName);
        PoolImpl pool = (PoolImpl) PoolManager.find(poolName);
        assertNotNull(pool);
        Connection conn1 = pool.acquireConnection(new ServerLocation(host, PORT2));
        assertNotNull(conn1);
        assertEquals(PORT2, conn1.getServer().getPort());
        ServerRegionProxy srp = new ServerRegionProxy(Region.SEPARATOR + REGION_NAME, pool);
        srp.clearOnForTestsOnly(conn1, new EventID(new byte[] { 1 }, 1, 1), null);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("while setting acquireConnections  " + ex);
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) Connection(org.apache.geode.cache.client.internal.Connection) Region(org.apache.geode.cache.Region) EventID(org.apache.geode.internal.cache.EventID) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) CacheException(org.apache.geode.cache.CacheException)

Example 50 with EventID

use of org.apache.geode.internal.cache.EventID in project geode by apache.

the class Bug36269DUnitTest method acquireConnectionsAndDestroyRegion.

public static void acquireConnectionsAndDestroyRegion(String host) {
    try {
        Connection desCon = pool.acquireConnection(new ServerLocation(host, PORT2));
        ServerRegionProxy srp = new ServerRegionProxy(Region.SEPARATOR + REGION_NAME, pool);
        srp.destroyRegionOnForTestsOnly(desCon, new EventID(new byte[] { 1 }, 1, 1), null);
    } catch (Exception ex) {
        Assert.fail("while setting acquireConnections", ex);
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) Connection(org.apache.geode.cache.client.internal.Connection) EventID(org.apache.geode.internal.cache.EventID)

Aggregations

EventID (org.apache.geode.internal.cache.EventID)147 Test (org.junit.Test)66 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)60 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)58 IOException (java.io.IOException)41 Map (java.util.Map)33 CacheException (org.apache.geode.cache.CacheException)31 Conflatable (org.apache.geode.internal.cache.Conflatable)29 LocalRegion (org.apache.geode.internal.cache.LocalRegion)23 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)20 HashMap (java.util.HashMap)16 Part (org.apache.geode.internal.cache.tier.sockets.Part)16 ByteBuffer (java.nio.ByteBuffer)14 Iterator (java.util.Iterator)14 List (java.util.List)14 LinkedHashMap (java.util.LinkedHashMap)13 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)13 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)13 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)13 ConcurrentMap (java.util.concurrent.ConcurrentMap)12