Search in sources :

Example 1 with SequenceIdAndExpirationObject

use of org.apache.geode.cache.client.internal.QueueStateImpl.SequenceIdAndExpirationObject in project geode by apache.

the class ReliableMessagingDUnitTest method waitForClientAck.

/**
   * Wait for acknowledgment from client, verify creation time is correct
   * 
   * @throws Exception
   */
public static void waitForClientAck() throws Exception {
    final long maxWaitTime = 30000;
    final long start = System.currentTimeMillis();
    Iterator iter = pool.getThreadIdToSequenceIdMap().entrySet().iterator();
    SequenceIdAndExpirationObject seo = null;
    if (!iter.hasNext()) {
        fail("map is empty");
    }
    Map.Entry entry = (Map.Entry) iter.next();
    seo = (SequenceIdAndExpirationObject) entry.getValue();
    for (; ; ) {
        if (seo.getAckSend()) {
            break;
        }
        assertTrue("Waited over " + maxWaitTime + " for client ack ", +(System.currentTimeMillis() - start) < maxWaitTime);
        sleep(1000);
    }
    LogWriterUtils.getLogWriter().info("seo = " + seo);
    assertTrue("Creation time " + creationTime + " supposed to be same as seo " + seo.getCreationTime(), creationTime == seo.getCreationTime());
}
Also used : SequenceIdAndExpirationObject(org.apache.geode.cache.client.internal.QueueStateImpl.SequenceIdAndExpirationObject) Iterator(java.util.Iterator) Map(java.util.Map)

Example 2 with SequenceIdAndExpirationObject

use of org.apache.geode.cache.client.internal.QueueStateImpl.SequenceIdAndExpirationObject in project geode by apache.

the class HAEventIdPropagationDUnitTest method assertThreadIdToSequenceIdMapHasEntryId.

/**
   * function to assert that the ThreadIdtoSequence id Map is not Null and has only one entry *
   */
public static Object assertThreadIdToSequenceIdMapHasEntryId() {
    Map map = pool.getThreadIdToSequenceIdMap();
    assertNotNull(map);
    // The map size can now be 1 or 2 because of the server thread putting
    // the marker in the queue. If it is 2, the first entry is the server
    // thread; the second is the client thread. If it is 1, the entry is the
    // client thread. The size changes because of the map.clear call below.
    assertTrue(map.size() != 0);
    // Set the entry to the last entry
    Map.Entry entry = null;
    for (Iterator threadIdToSequenceIdMapIterator = map.entrySet().iterator(); threadIdToSequenceIdMapIterator.hasNext(); ) {
        entry = (Map.Entry) threadIdToSequenceIdMapIterator.next();
    }
    ThreadIdentifier tid = (ThreadIdentifier) entry.getKey();
    SequenceIdAndExpirationObject seo = (SequenceIdAndExpirationObject) entry.getValue();
    long sequenceId = seo.getSequenceId();
    EventID evId = new EventID(tid.getMembershipID(), tid.getThreadID(), sequenceId);
    synchronized (map) {
        map.clear();
    }
    return evId;
}
Also used : SequenceIdAndExpirationObject(org.apache.geode.cache.client.internal.QueueStateImpl.SequenceIdAndExpirationObject) Iterator(java.util.Iterator) EventID(org.apache.geode.internal.cache.EventID) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with SequenceIdAndExpirationObject

use of org.apache.geode.cache.client.internal.QueueStateImpl.SequenceIdAndExpirationObject in project geode by apache.

the class EventIdOptimizationDUnitTest method assertThreadIdToSequenceIdMapHasEntryId.

/**
   * Function to assert that the ThreadIdtoSequence id Map is not Null and has only one entry.
   * 
   * @return - eventID object from the ThreadIdToSequenceIdMap
   */
public static Object assertThreadIdToSequenceIdMapHasEntryId() {
    Map map = pool.getThreadIdToSequenceIdMap();
    assertNotNull(map);
    // The map size can now be 1 or 2 because of the server thread putting
    // the marker in the queue. If it is 2, the first entry is the server
    // thread; the second is the client thread. If it is 1, the entry is the
    // client thread. The size changes because of the map.clear call below.
    assertTrue(map.size() != 0);
    // Set the entry to the last entry
    Map.Entry entry = null;
    for (Iterator threadIdToSequenceIdMapIterator = map.entrySet().iterator(); threadIdToSequenceIdMapIterator.hasNext(); ) {
        entry = (Map.Entry) threadIdToSequenceIdMapIterator.next();
    }
    ThreadIdentifier tid = (ThreadIdentifier) entry.getKey();
    SequenceIdAndExpirationObject seo = (SequenceIdAndExpirationObject) entry.getValue();
    long sequenceId = seo.getSequenceId();
    EventID evId = new EventID(tid.getMembershipID(), tid.getThreadID(), sequenceId);
    synchronized (map) {
        map.clear();
    }
    return evId;
}
Also used : SequenceIdAndExpirationObject(org.apache.geode.cache.client.internal.QueueStateImpl.SequenceIdAndExpirationObject) Iterator(java.util.Iterator) EventID(org.apache.geode.internal.cache.EventID) Map(java.util.Map)

Example 4 with SequenceIdAndExpirationObject

use of org.apache.geode.cache.client.internal.QueueStateImpl.SequenceIdAndExpirationObject in project geode by apache.

the class PutAllDUnitTest method assertThreadIdToSequenceIdMapHasEntryId.

/** function to assert that the ThreadIdtoSequence id Map is not Null and has only one entry **/
public static Object assertThreadIdToSequenceIdMapHasEntryId() {
    Map map = pool.getThreadIdToSequenceIdMap();
    assertNotNull(map);
    // The map size can now be 1 or 2 because of the server thread putting
    // the marker in the queue. If it is 2, the first entry is the server
    // thread; the second is the client thread. If it is 1, the entry is the
    // client thread. The size changes because of the map.clear call below.
    assertTrue(map.size() != 0);
    // Set the entry to the last entry
    Map.Entry entry = null;
    for (Iterator threadIdToSequenceIdMapIterator = map.entrySet().iterator(); threadIdToSequenceIdMapIterator.hasNext(); ) {
        entry = (Map.Entry) threadIdToSequenceIdMapIterator.next();
    }
    ThreadIdentifier tid = (ThreadIdentifier) entry.getKey();
    SequenceIdAndExpirationObject seo = (SequenceIdAndExpirationObject) entry.getValue();
    long sequenceId = seo.getSequenceId();
    EventID evId = new EventID(tid.getMembershipID(), tid.getThreadID(), sequenceId);
    synchronized (map) {
        map.clear();
    }
    return evId;
}
Also used : SequenceIdAndExpirationObject(org.apache.geode.cache.client.internal.QueueStateImpl.SequenceIdAndExpirationObject) Iterator(java.util.Iterator) EventID(org.apache.geode.internal.cache.EventID) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with SequenceIdAndExpirationObject

use of org.apache.geode.cache.client.internal.QueueStateImpl.SequenceIdAndExpirationObject in project geode by apache.

the class ReliableMessagingDUnitTest method setCreationTimeTidAndSeq.

public static void setCreationTimeTidAndSeq() {
    final Map map = pool.getThreadIdToSequenceIdMap();
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            synchronized (map) {
                return map.entrySet().size() > 0;
            }
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 10 * 1000, 200, true);
    Map.Entry entry;
    synchronized (map) {
        Iterator iter = map.entrySet().iterator();
        entry = (Map.Entry) iter.next();
    }
    SequenceIdAndExpirationObject seo = (SequenceIdAndExpirationObject) entry.getValue();
    assertFalse(seo.getAckSend());
    creationTime = seo.getCreationTime();
    LogWriterUtils.getLogWriter().info("seo is " + seo.toString());
    assertTrue("Creation time not set", creationTime != 0);
    Object[] args = new Object[] { ((ThreadIdentifier) entry.getKey()).getMembershipID(), new Long(((ThreadIdentifier) entry.getKey()).getThreadID()), new Long(seo.getSequenceId()) };
    server1.invoke(ReliableMessagingDUnitTest.class, "setTidAndSeq", args);
    server2.invoke(ReliableMessagingDUnitTest.class, "setTidAndSeq", args);
}
Also used : SequenceIdAndExpirationObject(org.apache.geode.cache.client.internal.QueueStateImpl.SequenceIdAndExpirationObject) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ThreadIdentifier(org.apache.geode.internal.cache.ha.ThreadIdentifier) Iterator(java.util.Iterator) SequenceIdAndExpirationObject(org.apache.geode.cache.client.internal.QueueStateImpl.SequenceIdAndExpirationObject) Map(java.util.Map)

Aggregations

Iterator (java.util.Iterator)5 Map (java.util.Map)5 SequenceIdAndExpirationObject (org.apache.geode.cache.client.internal.QueueStateImpl.SequenceIdAndExpirationObject)5 EventID (org.apache.geode.internal.cache.EventID)3 LinkedHashMap (java.util.LinkedHashMap)2 ThreadIdentifier (org.apache.geode.internal.cache.ha.ThreadIdentifier)1 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)1