Search in sources :

Example 1 with QueryMessage

use of org.apache.geode.internal.cache.partitioned.QueryMessage in project geode by apache.

the class PartitionedRegionQueryDUnitTest method testRebalanceDuringQueryEvaluation.

/**
   * Test of bug 43102. 1. Buckets are created on several nodes 2. A query is started 3. While the
   * query is executing, several buckets are moved.
   */
@Test
public void testRebalanceDuringQueryEvaluation() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    createAccessor(vm0);
    createPR(vm1);
    createBuckets(vm1);
    createPR(vm2);
    // Add a listener that will trigger a rebalance
    // as soon as the query arrives on this node.
    vm1.invoke(new SerializableRunnable("add listener") {

        public void run() {
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof QueryMessage) {
                        RebalanceOperation rebalance = getCache().getResourceManager().createRebalanceFactory().start();
                        // wait for the rebalance
                        try {
                            rebalanceResults.compareAndSet(null, rebalance.getResults());
                        } catch (CancellationException e) {
                        // ignore
                        } catch (InterruptedException e) {
                        // ignore
                        }
                    }
                }
            });
        }
    });
    executeQuery(vm0);
    vm1.invoke(new SerializableRunnable("check rebalance happened") {

        public void run() {
            assertNotNull(rebalanceResults.get());
            assertEquals(5, rebalanceResults.get().getTotalBucketTransfersCompleted());
        }
    });
}
Also used : QueryMessage(org.apache.geode.internal.cache.partitioned.QueryMessage) RebalanceOperation(org.apache.geode.cache.control.RebalanceOperation) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) CancellationException(java.util.concurrent.CancellationException) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Aggregations

CancellationException (java.util.concurrent.CancellationException)1 RebalanceOperation (org.apache.geode.cache.control.RebalanceOperation)1 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)1 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)1 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)1 DistributionMessageObserver (org.apache.geode.distributed.internal.DistributionMessageObserver)1 QueryMessage (org.apache.geode.internal.cache.partitioned.QueryMessage)1 Host (org.apache.geode.test.dunit.Host)1 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)1 VM (org.apache.geode.test.dunit.VM)1 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)1 Test (org.junit.Test)1