Search in sources :

Example 1 with RequestImageMessage

use of org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage in project geode by apache.

the class RequestImageMessageTest method shouldBeMockable.

@Test
public void shouldBeMockable() throws Exception {
    RequestImageMessage mockRequestImageMessage = mock(RequestImageMessage.class);
    when(mockRequestImageMessage.getProcessorType()).thenReturn(1);
    assertThat(mockRequestImageMessage.getProcessorType()).isEqualTo(1);
}
Also used : RequestImageMessage(org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 2 with RequestImageMessage

use of org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage in project geode by apache.

the class Bug41091DUnitTest method test.

@Test
public void test() {
    final Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM vm3 = host.getVM(3);
    final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    // We need to use our own locator because we need enable network partition detection.
    startLocatorInVM(vm3, locatorPort);
    try {
        final SerializableRunnable createRegion = new SerializableRunnable("create the region") {

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

                    @Override
                    public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                        if (message instanceof RequestImageMessage) {
                            RequestImageMessage rim = (RequestImageMessage) message;
                            Region region = getCache().getRegion(rim.regionPath);
                            if (region instanceof BucketRegion) {
                                // We can no longer do any puts until the bucket is completely created,
                                // so this will hang
                                // getCache().getRegion("region").put(113, "b");
                                getCache().close();
                            }
                        }
                    }
                });
                Properties props = new Properties();
                props.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "true");
                props.setProperty(LOCATORS, NetworkUtils.getServerHostName(host) + "[" + locatorPort + "]");
                getSystem(props);
                Cache cache = getCache();
                AttributesFactory af = new AttributesFactory();
                PartitionAttributesFactory paf = new PartitionAttributesFactory();
                paf.setRedundantCopies(1);
                af.setPartitionAttributes(paf.create());
                cache.createRegion("region", af.create());
            }
        };
        vm0.invoke(createRegion);
        vm1.invoke(createRegion);
        vm2.invoke(new SerializableRunnable("create an entry") {

            public void run() {
                Properties props = new Properties();
                props.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "true");
                props.setProperty(LOCATORS, NetworkUtils.getServerHostName(host) + "[" + locatorPort + "]");
                getSystem(props);
                Cache cache = getCache();
                AttributesFactory af = new AttributesFactory();
                PartitionAttributesFactory paf = new PartitionAttributesFactory();
                paf.setRedundantCopies(1);
                paf.setLocalMaxMemory(0);
                af.setPartitionAttributes(paf.create());
                Region region = cache.createRegion("region", af.create());
                region.put(Integer.valueOf(0), "a");
            }
        });
    } finally {
        SerializableRunnable stopLocator = new SerializableRunnable("Stop locator") {

            public void run() {
                assertTrue(Locator.hasLocator());
                Locator.getLocator().stop();
                assertFalse(Locator.hasLocator());
            }
        };
        vm3.invoke(stopLocator);
    }
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) RequestImageMessage(org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 3 with RequestImageMessage

use of org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage in project geode by apache.

the class PersistentColocatedPartitionedRegionDUnitTest method testCrashDuringRedundancySatisfaction.

/**
   * Test what happens when we crash in the middle of satisfying redundancy for a colocated bucket.
   * 
   * @throws Throwable
   */
// This test method is disabled because it is failing
// periodically and causing cruise control failures
// See bug #46748
@Test
public void testCrashDuringRedundancySatisfaction() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    SerializableRunnable createPRs = new SerializableRunnable("region1") {

        public void run() {
            Cache cache = getCache();
            DiskStore ds = cache.findDiskStore("disk");
            if (ds == null) {
                ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
            }
            AttributesFactory af = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(1);
            // Workaround for 44414 - disable recovery delay so we shutdown
            // vm1 at a predictable point.
            paf.setRecoveryDelay(-1);
            paf.setStartupRecoveryDelay(-1);
            af.setPartitionAttributes(paf.create());
            af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
            af.setDiskStoreName("disk");
            cache.createRegion(PR_REGION_NAME, af.create());
            paf.setColocatedWith(PR_REGION_NAME);
            af.setPartitionAttributes(paf.create());
            cache.createRegion("region2", af.create());
        }
    };
    // Create the PR on vm0
    vm0.invoke(createPRs);
    // Create some buckets.
    createData(vm0, 0, NUM_BUCKETS, "a");
    createData(vm0, 0, NUM_BUCKETS, "a", "region2");
    vm1.invoke(createPRs);
    // We shouldn't have created any buckets in vm1 yet.
    assertEquals(Collections.emptySet(), getBucketList(vm1));
    // Add an observer that will disconnect before allowing the peer to
    // GII a colocated bucket. This should leave the peer with only the parent
    // bucket
    vm0.invoke(new SerializableRunnable() {

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

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof RequestImageMessage) {
                        if (((RequestImageMessage) message).regionPath.contains("region2")) {
                            DistributionMessageObserver.setInstance(null);
                            disconnectFromDS();
                        }
                    }
                }
            });
        }
    });
    IgnoredException ex = IgnoredException.addIgnoredException("PartitionOfflineException", vm1);
    try {
        // as we satisfy redundancy with vm1.
        try {
            RebalanceResults rr = rebalance(vm1);
        } catch (Exception expected) {
            // disconnect
            if (!(expected.getCause() instanceof PartitionOfflineException)) {
                throw expected;
            }
        }
        // Wait for vm0 to be closed by the callback
        vm0.invoke(new SerializableCallable() {

            public Object call() throws Exception {
                Wait.waitForCriterion(new WaitCriterion() {

                    public boolean done() {
                        InternalDistributedSystem ds = basicGetSystem();
                        return ds == null || !ds.isConnected();
                    }

                    public String description() {
                        return "DS did not disconnect";
                    }
                }, MAX_WAIT, 100, true);
                return null;
            }
        });
        // close the cache in vm1
        SerializableCallable disconnectFromDS = new SerializableCallable() {

            public Object call() throws Exception {
                disconnectFromDS();
                return null;
            }
        };
        vm1.invoke(disconnectFromDS);
        // Make sure vm0 is disconnected. This avoids a race where we
        // may still in the process of disconnecting even though the our async listener
        // found the system was disconnected
        vm0.invoke(disconnectFromDS);
    } finally {
        ex.remove();
    }
    // Create the cache and PRs on both members
    AsyncInvocation async0 = vm0.invokeAsync(createPRs);
    AsyncInvocation async1 = vm1.invokeAsync(createPRs);
    async0.getResult(MAX_WAIT);
    async1.getResult(MAX_WAIT);
    // Make sure the data was recovered correctly
    checkData(vm0, 0, NUM_BUCKETS, "a");
    // Workaround for bug 46748.
    checkData(vm0, 0, NUM_BUCKETS, "a", "region2");
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) RequestImageMessage(org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) IgnoredException(org.apache.geode.test.dunit.IgnoredException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) RMIException(org.apache.geode.test.dunit.RMIException) CacheClosedException(org.apache.geode.cache.CacheClosedException) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) IOException(java.io.IOException) DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) IgnoredException(org.apache.geode.test.dunit.IgnoredException) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) RebalanceResults(org.apache.geode.cache.control.RebalanceResults) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 4 with RequestImageMessage

use of org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage in project geode by apache.

the class PersistentPartitionedRegionDUnitTest method testCrashDuringBucketGII.

/**
   * A test for bug 41436. If the GII source crashes before the GII is complete, we need to make
   * sure that later we can recover redundancy.
   */
@Test
public void testCrashDuringBucketGII() {
    IgnoredException.addIgnoredException("PartitionOfflineException");
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    createPR(vm0, 1);
    createData(vm0, 0, 1, "value");
    // Add an observer which will close the cache when the GII starts
    vm0.invoke(new SerializableRunnable("Set crashing observer") {

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

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof RequestImageMessage) {
                        RequestImageMessage rim = (RequestImageMessage) message;
                        if (rim.regionPath.contains("_0")) {
                            DistributionMessageObserver.setInstance(null);
                            getCache().close();
                        }
                    }
                }
            });
        }
    });
    createPR(vm1, 1);
    // Make sure vm1 didn't create the bucket
    assertEquals(Collections.emptySet(), getBucketList(vm1));
    createPR(vm0, 1, 0);
    // Make sure vm0 recovers the bucket
    assertEquals(Collections.singleton(0), getBucketList(vm0));
    // vm1 should satisfy redundancy for the bucket as well
    assertEquals(Collections.singleton(0), getBucketList(vm1));
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) RequestImageMessage(org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 5 with RequestImageMessage

use of org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage in project geode by apache.

the class GIIDeltaDUnitTest method checkIfFullGII.

private void checkIfFullGII(VM vm, final String regionName, final byte[] remote_rvv_bytearray, final boolean expectFullGII) {
    SerializableRunnable checkIfFullGII = new SerializableRunnable("check if full gii") {

        public void run() {
            DistributedRegion rr = (DistributedRegion) getCache().getRegion(regionName);
            ByteArrayInputStream bais = new ByteArrayInputStream(remote_rvv_bytearray);
            RegionVersionVector remote_rvv = null;
            try {
                remote_rvv = DataSerializer.readObject(new DataInputStream(bais));
            } catch (IOException e) {
                Assert.fail("Unexpected exception", e);
            } catch (ClassNotFoundException e) {
                Assert.fail("Unexpected exception", e);
            }
            RequestImageMessage rim = new RequestImageMessage();
            rim.setSender(R_ID);
            boolean isFullGII = rim.goWithFullGII(rr, remote_rvv);
            assertEquals(expectFullGII, isFullGII);
        }
    };
    vm.invoke(checkIfFullGII);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) RequestImageMessage(org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage)

Aggregations

RequestImageMessage (org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage)9 Test (org.junit.Test)8 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)7 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)7 DistributionMessageObserver (org.apache.geode.distributed.internal.DistributionMessageObserver)7 Host (org.apache.geode.test.dunit.Host)7 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)7 VM (org.apache.geode.test.dunit.VM)7 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)7 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)6 IOException (java.io.IOException)4 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)4 IgnoredException (org.apache.geode.test.dunit.IgnoredException)4 Cache (org.apache.geode.cache.Cache)3 CacheClosedException (org.apache.geode.cache.CacheClosedException)3 AdminException (org.apache.geode.admin.AdminException)2 AttributesFactory (org.apache.geode.cache.AttributesFactory)2 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)2 Region (org.apache.geode.cache.Region)2 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)2