Search in sources :

Example 11 with RegionQueue

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

the class ParallelGatewaySenderQueueOverflowDUnitTest method test_ValidateParallelGatewaySenderQueueAttributes_1.

/**
   * Test to validate that ParallelGatewaySenderQueue diskSynchronous attribute when persistence of
   * sender is enabled.
   */
@Ignore("TODO: test is disabled")
@Test
public void test_ValidateParallelGatewaySenderQueueAttributes_1() {
    Integer localLocPort = (Integer) vm0.invoke(() -> WANTestBase.createFirstLocatorWithDSId(1));
    Integer remoteLocPort = (Integer) vm1.invoke(() -> WANTestBase.createFirstRemoteLocator(2, localLocPort));
    WANTestBase test = new WANTestBase();
    Properties props = test.getDistributedSystemProperties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "localhost[" + localLocPort + "]");
    InternalDistributedSystem ds = test.getSystem(props);
    cache = CacheFactory.create(ds);
    File directory = new File("TKSender" + "_disk_" + System.currentTimeMillis() + "_" + VM.getCurrentVMNum());
    directory.mkdir();
    File[] dirs1 = new File[] { directory };
    DiskStoreFactory dsf = cache.createDiskStoreFactory();
    dsf.setDiskDirs(dirs1);
    DiskStore diskStore = dsf.create("FORNY");
    GatewaySenderFactory fact = cache.createGatewaySenderFactory();
    // set parallel to true
    fact.setParallel(true);
    fact.setBatchConflationEnabled(true);
    fact.setBatchSize(200);
    fact.setBatchTimeInterval(300);
    // enable the persistence
    fact.setPersistenceEnabled(true);
    fact.setDiskSynchronous(true);
    fact.setDiskStoreName("FORNY");
    fact.setMaximumQueueMemory(200);
    fact.setAlertThreshold(1200);
    GatewayEventFilter myEventFilter1 = new MyGatewayEventFilter1();
    fact.addGatewayEventFilter(myEventFilter1);
    GatewayTransportFilter myStreamFilter1 = new MyGatewayTransportFilter1();
    fact.addGatewayTransportFilter(myStreamFilter1);
    GatewayTransportFilter myStreamFilter2 = new MyGatewayTransportFilter2();
    fact.addGatewayTransportFilter(myStreamFilter2);
    final IgnoredException exTKSender = IgnoredException.addIgnoredException("Could not connect");
    try {
        GatewaySender sender1 = fact.create("TKSender", 2);
        AttributesFactory factory = new AttributesFactory();
        factory.addGatewaySenderId(sender1.getId());
        factory.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
        Region region = cache.createRegionFactory(factory.create()).create("test_ValidateGatewaySenderAttributes");
        Set<GatewaySender> senders = cache.getGatewaySenders();
        assertEquals(senders.size(), 1);
        GatewaySender gatewaySender = senders.iterator().next();
        Set<RegionQueue> regionQueues = ((AbstractGatewaySender) gatewaySender).getQueues();
        assertEquals(regionQueues.size(), 1);
        RegionQueue regionQueue = regionQueues.iterator().next();
        assertEquals(true, regionQueue.getRegion().getAttributes().isDiskSynchronous());
    } finally {
        exTKSender.remove();
    }
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) WANTestBase(org.apache.geode.internal.cache.wan.WANTestBase) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) MyGatewayTransportFilter1(org.apache.geode.cache30.MyGatewayTransportFilter1) MyGatewayTransportFilter2(org.apache.geode.cache30.MyGatewayTransportFilter2) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) RegionQueue(org.apache.geode.internal.cache.RegionQueue) DiskStore(org.apache.geode.cache.DiskStore) AttributesFactory(org.apache.geode.cache.AttributesFactory) MyGatewayEventFilter1(org.apache.geode.cache30.MyGatewayEventFilter1) GatewaySenderFactory(org.apache.geode.cache.wan.GatewaySenderFactory) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Region(org.apache.geode.cache.Region) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) GatewayTransportFilter(org.apache.geode.cache.wan.GatewayTransportFilter) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) File(java.io.File) GatewayEventFilter(org.apache.geode.cache.wan.GatewayEventFilter) Ignore(org.junit.Ignore) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 12 with RegionQueue

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

the class MyGatewayEventSubstitutionFilter method waitForAsyncEventQueueSize.

/**
   * This method verifies the queue size of a ParallelGatewaySender. For ParallelGatewaySender
   * conflation happens in a separate thread, hence test code needs to wait for some time for
   * expected result
   * 
   * @param asyncQueueId Async Queue ID
   * @param numQueueEntries expected number of Queue entries
   * @throws Exception
   */
public static void waitForAsyncEventQueueSize(String asyncQueueId, final int numQueueEntries) throws Exception {
    AsyncEventQueue theAsyncEventQueue = null;
    Set<AsyncEventQueue> asyncEventChannels = cache.getAsyncEventQueues();
    for (AsyncEventQueue asyncChannel : asyncEventChannels) {
        if (asyncQueueId.equals(asyncChannel.getId())) {
            theAsyncEventQueue = asyncChannel;
        }
    }
    GatewaySender sender = ((AsyncEventQueueImpl) theAsyncEventQueue).getSender();
    if (sender.isParallel()) {
        final Set<RegionQueue> queues = ((AbstractGatewaySender) sender).getQueues();
        Wait.waitForCriterion(new WaitCriterion() {

            public String description() {
                return "Waiting for EventQueue size to be " + numQueueEntries;
            }

            public boolean done() {
                boolean done = numQueueEntries == queues.toArray(new RegionQueue[queues.size()])[0].getRegion().size();
                return done;
            }
        }, MAX_WAIT, 500, true);
    } else {
        throw new Exception("This method should be used for only ParallelGatewaySender,SerialGatewaySender should use checkAsyncEventQueueSize() method instead");
    }
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) AsyncEventQueueImpl(org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl) RegionQueue(org.apache.geode.internal.cache.RegionQueue) IgnoredException(org.apache.geode.test.dunit.IgnoredException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) CacheClosedException(org.apache.geode.cache.CacheClosedException) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) IOException(java.io.IOException)

Example 13 with RegionQueue

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

the class MyGatewayEventSubstitutionFilter method checkAsyncEventQueueSize.

public static void checkAsyncEventQueueSize(String asyncQueueId, int numQueueEntries) {
    AsyncEventQueue theAsyncEventQueue = null;
    Set<AsyncEventQueue> asyncEventChannels = cache.getAsyncEventQueues();
    for (AsyncEventQueue asyncChannel : asyncEventChannels) {
        if (asyncQueueId.equals(asyncChannel.getId())) {
            theAsyncEventQueue = asyncChannel;
        }
    }
    GatewaySender sender = ((AsyncEventQueueImpl) theAsyncEventQueue).getSender();
    if (sender.isParallel()) {
        Set<RegionQueue> queues = ((AbstractGatewaySender) sender).getQueues();
        assertEquals(numQueueEntries, queues.toArray(new RegionQueue[queues.size()])[0].getRegion().size());
    } else {
        Set<RegionQueue> queues = ((AbstractGatewaySender) sender).getQueues();
        int size = 0;
        for (RegionQueue q : queues) {
            size += q.size();
        }
        assertEquals(numQueueEntries, size);
    }
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) AsyncEventQueueImpl(org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl) RegionQueue(org.apache.geode.internal.cache.RegionQueue)

Example 14 with RegionQueue

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

the class HARegionQueueJUnitTest method testQRM.

/**
   * Tests whether the QRM message removes the events correctly from the DACE & Conflation Map. The
   * events which are of ID greater than that contained in QRM should stay
   */
@Test
public void testQRM() throws Exception {
    RegionQueue regionqueue = createHARegionQueue(this.testName.getMethodName());
    for (int i = 0; i < 10; ++i) {
        regionqueue.put(new ConflatableObject("key" + (i + 1), "value", new EventID(new byte[] { 1 }, 1, i + 1), true, this.testName.getMethodName()));
    }
    EventID qrmID = new EventID(new byte[] { 1 }, 1, 5);
    ((HARegionQueue) regionqueue).removeDispatchedEvents(qrmID);
    Map conflationMap = ((HARegionQueue) regionqueue).getConflationMapForTesting();
    assertThat(((Map) conflationMap.get(this.testName.getMethodName())).size(), is(5));
    Set availableIDs = ((HARegionQueue) regionqueue).getAvalaibleIds();
    Set counters = ((HARegionQueue) regionqueue).getCurrentCounterSet(qrmID);
    assertThat(availableIDs.size(), is(5));
    assertThat(counters.size(), is(5));
    for (int i = 5; i < 10; ++i) {
        assertThat(((Map) (conflationMap.get(this.testName.getMethodName()))).containsKey("key" + (i + 1)), is(true));
        assertThat(availableIDs.contains((long) (i + 1)), is(true));
        assertThat(counters.contains((long) (i + 1)), is(true));
    }
    Region rgn = ((HARegionQueue) regionqueue).getRegion();
    assertThat(rgn.keySet().size(), is(6));
}
Also used : Set(java.util.Set) EventID(org.apache.geode.internal.cache.EventID) Region(org.apache.geode.cache.Region) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RegionQueue(org.apache.geode.internal.cache.RegionQueue) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 15 with RegionQueue

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

the class HARegionQueueJUnitTest method testConcurrentEventExpiryAndTake.

/**
   * The basis of HARegionQueue's Add & remove operations etc , is that the event being added first
   * goes into DACE , Region etc and finally it is published by adding into the available IDs Set.
   * Similarly if an event is to be removed it should first be removed from availableIDs set & then
   * from behind the scenes. It will be the responsibility of the thread removing from available IDs
   * successfully which will remove the entry from all other places. Now if the expiry task makes
   * the event from underlying null before removing from available IDs , there is a potential
   * violation. This test will validate that behaviour
   */
@Test
public void testConcurrentEventExpiryAndTake() throws Exception {
    AtomicBoolean complete = new AtomicBoolean(false);
    AtomicBoolean expiryCalled = new AtomicBoolean(false);
    AtomicBoolean allowExpiryToProceed = new AtomicBoolean(false);
    HARegionQueueAttributes haa = new HARegionQueueAttributes();
    haa.setExpiryTime(3);
    RegionQueue regionqueue = new HARegionQueue.TestOnlyHARegionQueue(this.testName.getMethodName(), this.cache, haa) {

        @Override
        CacheListener createCacheListenerForHARegion() {
            return new CacheListenerAdapter() {

                @Override
                public void afterInvalidate(EntryEvent event) {
                    if (event.getKey() instanceof Long) {
                        synchronized (HARegionQueueJUnitTest.this) {
                            expiryCalled.set(true);
                            HARegionQueueJUnitTest.this.notifyAll();
                        }
                        Thread.yield();
                        synchronized (HARegionQueueJUnitTest.this) {
                            while (!allowExpiryToProceed.get()) {
                                try {
                                    HARegionQueueJUnitTest.this.wait();
                                } catch (InterruptedException e) {
                                    errorCollector.addError(e);
                                    break;
                                }
                            }
                        }
                        try {
                            expireTheEventOrThreadIdentifier(event);
                        } catch (CacheException e) {
                            errorCollector.addError(e);
                        } finally {
                            synchronized (HARegionQueueJUnitTest.this) {
                                complete.set(true);
                                HARegionQueueJUnitTest.this.notifyAll();
                            }
                        }
                    }
                }
            };
        }
    };
    EventID ev1 = new EventID(new byte[] { 1 }, 1, 1);
    Conflatable cf1 = new ConflatableObject("key", "value", ev1, true, this.testName.getMethodName());
    regionqueue.put(cf1);
    synchronized (this) {
        while (!expiryCalled.get()) {
            wait();
        }
    }
    try {
        Object o = regionqueue.take();
        assertThat(o, nullValue());
    } catch (Exception e) {
        throw new AssertionError("Test failed due to exception ", e);
    } finally {
        synchronized (this) {
            allowExpiryToProceed.set(true);
            notifyAll();
        }
    }
    synchronized (this) {
        while (!complete.get()) {
            wait();
        }
    }
}
Also used : CacheException(org.apache.geode.cache.CacheException) RegionQueue(org.apache.geode.internal.cache.RegionQueue) RegionExistsException(org.apache.geode.cache.RegionExistsException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) EntryEvent(org.apache.geode.cache.EntryEvent) EventID(org.apache.geode.internal.cache.EventID) Conflatable(org.apache.geode.internal.cache.Conflatable) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

RegionQueue (org.apache.geode.internal.cache.RegionQueue)39 GatewaySender (org.apache.geode.cache.wan.GatewaySender)28 IgnoredException (org.apache.geode.test.dunit.IgnoredException)8 Properties (java.util.Properties)7 AttributesFactory (org.apache.geode.cache.AttributesFactory)7 Test (org.junit.Test)7 Region (org.apache.geode.cache.Region)6 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)6 ConcurrentParallelGatewaySenderQueue (org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 CacheListener (org.apache.geode.cache.CacheListener)4 AsyncEventQueue (org.apache.geode.cache.asyncqueue.AsyncEventQueue)4 AsyncEventQueueImpl (org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl)4 BucketRegion (org.apache.geode.internal.cache.BucketRegion)4 AbstractGatewaySender (org.apache.geode.internal.cache.wan.AbstractGatewaySender)4 RegionAttributes (org.apache.geode.cache.RegionAttributes)3 GatewayEventFilter (org.apache.geode.cache.wan.GatewayEventFilter)3 GatewaySenderFactory (org.apache.geode.cache.wan.GatewaySenderFactory)3 GatewayTransportFilter (org.apache.geode.cache.wan.GatewayTransportFilter)3 MyGatewayEventFilter1 (org.apache.geode.cache30.MyGatewayEventFilter1)3