Search in sources :

Example 26 with IgnoredException

use of org.apache.geode.test.dunit.IgnoredException in project geode by apache.

the class MyGatewayEventSubstitutionFilter method killSender.

public static Boolean killSender(String senderId) {
    final IgnoredException exln = IgnoredException.addIgnoredException("Could not connect");
    IgnoredException exp = IgnoredException.addIgnoredException(CacheClosedException.class.getName());
    IgnoredException exp1 = IgnoredException.addIgnoredException(ForceReattemptException.class.getName());
    try {
        Set<GatewaySender> senders = cache.getGatewaySenders();
        AbstractGatewaySender sender = null;
        for (GatewaySender s : senders) {
            if (s.getId().equals(senderId)) {
                sender = (AbstractGatewaySender) s;
                break;
            }
        }
        if (sender.isPrimary()) {
            LogWriterUtils.getLogWriter().info("Gateway sender is killed by a test");
            cache.getDistributedSystem().disconnect();
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    } finally {
        exp.remove();
        exp1.remove();
        exln.remove();
    }
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) CacheClosedException(org.apache.geode.cache.CacheClosedException)

Example 27 with IgnoredException

use of org.apache.geode.test.dunit.IgnoredException in project geode by apache.

the class MyGatewayEventSubstitutionFilter method createReplicatedRegionWithSenderAndAsyncEventQueue.

public static void createReplicatedRegionWithSenderAndAsyncEventQueue(String regionName, String senderIds, String asyncChannelId, Boolean offHeap) {
    IgnoredException exp = IgnoredException.addIgnoredException(ForceReattemptException.class.getName());
    try {
        AttributesFactory fact = new AttributesFactory();
        if (senderIds != null) {
            StringTokenizer tokenizer = new StringTokenizer(senderIds, ",");
            while (tokenizer.hasMoreTokens()) {
                String senderId = tokenizer.nextToken();
                fact.addGatewaySenderId(senderId);
            }
        }
        fact.setDataPolicy(DataPolicy.REPLICATE);
        fact.setOffHeap(offHeap);
        fact.setScope(Scope.DISTRIBUTED_ACK);
        RegionFactory regionFactory = cache.createRegionFactory(fact.create());
        regionFactory.addAsyncEventQueueId(asyncChannelId);
        Region r = regionFactory.create(regionName);
        assertNotNull(r);
    } finally {
        exp.remove();
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionFactory(org.apache.geode.cache.RegionFactory) IgnoredException(org.apache.geode.test.dunit.IgnoredException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region)

Example 28 with IgnoredException

use of org.apache.geode.test.dunit.IgnoredException in project geode by apache.

the class MyGatewayEventSubstitutionFilter method createSender.

public static void createSender(String dsName, int remoteDsId, boolean isParallel, Integer maxMemory, Integer batchSize, boolean isConflation, boolean isPersistent, GatewayEventFilter filter, boolean isManulaStart) {
    final IgnoredException exln = IgnoredException.addIgnoredException("Could not connect");
    try {
        File persistentDirectory = new File(dsName + "_disk_" + System.currentTimeMillis() + "_" + VM.getCurrentVMNum());
        persistentDirectory.mkdir();
        DiskStoreFactory dsf = cache.createDiskStoreFactory();
        File[] dirs1 = new File[] { persistentDirectory };
        if (isParallel) {
            GatewaySenderFactory gateway = cache.createGatewaySenderFactory();
            gateway.setParallel(true);
            gateway.setMaximumQueueMemory(maxMemory);
            gateway.setBatchSize(batchSize);
            gateway.setManualStart(isManulaStart);
            // set dispatcher threads
            gateway.setDispatcherThreads(numDispatcherThreadsForTheRun);
            ((InternalGatewaySenderFactory) gateway).setLocatorDiscoveryCallback(new MyLocatorCallback());
            if (filter != null) {
                eventFilter = filter;
                gateway.addGatewayEventFilter(filter);
            }
            if (isPersistent) {
                gateway.setPersistenceEnabled(true);
                gateway.setDiskStoreName(dsf.setDiskDirs(dirs1).create(dsName).getName());
            } else {
                DiskStore store = dsf.setDiskDirs(dirs1).create(dsName);
                gateway.setDiskStoreName(store.getName());
            }
            gateway.setBatchConflationEnabled(isConflation);
            gateway.create(dsName, remoteDsId);
        } else {
            GatewaySenderFactory gateway = cache.createGatewaySenderFactory();
            gateway.setMaximumQueueMemory(maxMemory);
            gateway.setBatchSize(batchSize);
            gateway.setManualStart(isManulaStart);
            // set dispatcher threads
            gateway.setDispatcherThreads(numDispatcherThreadsForTheRun);
            ((InternalGatewaySenderFactory) gateway).setLocatorDiscoveryCallback(new MyLocatorCallback());
            if (filter != null) {
                eventFilter = filter;
                gateway.addGatewayEventFilter(filter);
            }
            gateway.setBatchConflationEnabled(isConflation);
            if (isPersistent) {
                gateway.setPersistenceEnabled(true);
                gateway.setDiskStoreName(dsf.setDiskDirs(dirs1).create(dsName).getName());
            } else {
                DiskStore store = dsf.setDiskDirs(dirs1).create(dsName);
                gateway.setDiskStoreName(store.getName());
            }
            gateway.create(dsName, remoteDsId);
        }
    } finally {
        exln.remove();
    }
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) GatewaySenderFactory(org.apache.geode.cache.wan.GatewaySenderFactory) IgnoredException(org.apache.geode.test.dunit.IgnoredException) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory)

Example 29 with IgnoredException

use of org.apache.geode.test.dunit.IgnoredException in project geode by apache.

the class MyGatewayEventSubstitutionFilter method validateRegionSize.

public static void validateRegionSize(String regionName, final int regionSize) {
    IgnoredException exp = IgnoredException.addIgnoredException(ForceReattemptException.class.getName());
    IgnoredException exp1 = IgnoredException.addIgnoredException(CacheClosedException.class.getName());
    try {
        final Region r = cache.getRegion(Region.SEPARATOR + regionName);
        assertNotNull(r);
        WaitCriterion wc = new WaitCriterion() {

            public boolean done() {
                if (r.keySet().size() == regionSize) {
                    return true;
                }
                return false;
            }

            public String description() {
                return "Expected region entries: " + regionSize + " but actual entries: " + r.keySet().size() + " present region keyset " + r.keySet();
            }
        };
        Wait.waitForCriterion(wc, 240000, 500, true);
    } finally {
        exp.remove();
        exp1.remove();
    }
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) IgnoredException(org.apache.geode.test.dunit.IgnoredException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) CacheClosedException(org.apache.geode.cache.CacheClosedException)

Example 30 with IgnoredException

use of org.apache.geode.test.dunit.IgnoredException in project geode by apache.

the class MyGatewayEventSubstitutionFilter method doNextPuts.

public static void doNextPuts(String regionName, int start, int numPuts) {
    // waitForSitesToUpdate();
    IgnoredException exp = IgnoredException.addIgnoredException(CacheClosedException.class.getName());
    try {
        Region r = cache.getRegion(Region.SEPARATOR + regionName);
        assertNotNull(r);
        for (long i = start; i < numPuts; i++) {
            r.put(i, i);
        }
    } finally {
        exp.remove();
    }
}
Also used : IgnoredException(org.apache.geode.test.dunit.IgnoredException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) CacheClosedException(org.apache.geode.cache.CacheClosedException)

Aggregations

IgnoredException (org.apache.geode.test.dunit.IgnoredException)142 Test (org.junit.Test)89 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)71 Region (org.apache.geode.cache.Region)46 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)46 VM (org.apache.geode.test.dunit.VM)43 Host (org.apache.geode.test.dunit.Host)38 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)34 AttributesFactory (org.apache.geode.cache.AttributesFactory)30 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)28 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)23 IOException (java.io.IOException)21 CacheClosedException (org.apache.geode.cache.CacheClosedException)21 LocalRegion (org.apache.geode.internal.cache.LocalRegion)20 PartitionOfflineException (org.apache.geode.cache.persistence.PartitionOfflineException)16 RMIException (org.apache.geode.test.dunit.RMIException)15 GatewaySender (org.apache.geode.cache.wan.GatewaySender)14 BucketRegion (org.apache.geode.internal.cache.BucketRegion)14 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)14 CacheXmlException (org.apache.geode.cache.CacheXmlException)12