Search in sources :

Example 36 with Cache

use of org.apache.geode.cache.Cache in project geode by apache.

the class ClusterConfigurationDUnitTest method testDestroyExtensions.

/**
   * Tests for {@link Extension}, {@link Extensible}, {@link XmlParser}, {@link XmlGenerator},
   * {@link XmlEntity} as it applies to Extensions. Asserts that Mock Extension is created and
   * destroyed on region and cache.
   * 
   * @since GemFire 8.1
   */
// GEODE-1333
@Category(FlakyTest.class)
@Test
public void testDestroyExtensions() throws Exception {
    Object[] result = setup();
    final int locatorPort = (Integer) result[0];
    createRegion(REPLICATE_REGION, RegionShortcut.REPLICATE, null);
    createMockRegionExtension(REPLICATE_REGION, "value1");
    destroyMockRegionExtension(REPLICATE_REGION);
    createMockCacheExtension("value1");
    destroyMockCacheExtension();
    // Start a new member which receives the shared configuration
    // Verify the config creation on this member
    final String newMemberWorkingDir = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + newMember;
    VM newMember = getHost(0).getVM(2);
    newMember.invoke(() -> {
        Properties localProps = new Properties();
        File workingDir = new File(newMemberWorkingDir);
        workingDir.mkdirs();
        localProps.setProperty(MCAST_PORT, "0");
        localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
        localProps.setProperty(NAME, ClusterConfigurationDUnitTest.newMember);
        localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
        localProps.setProperty(DEPLOY_WORKING_DIR, workingDir.getCanonicalPath());
        getSystem(localProps);
        InternalCache cache = getCache();
        assertNotNull(cache);
        Region<?, ?> region1 = cache.getRegion(REPLICATE_REGION);
        assertNotNull(region1);
        // MockRegionExtension verification
        @SuppressWarnings("unchecked") final Extensible<Region<?, ?>> extensibleRegion = (Extensible<Region<?, ?>>) region1;
        // Should not be any region extensions
        assertTrue(!extensibleRegion.getExtensionPoint().getExtensions().iterator().hasNext());
        // MockCacheExtension verification
        @SuppressWarnings("unchecked") final Extensible<Cache> extensibleCache = (Extensible<Cache>) cache;
        // Should not be any cache extensions
        assertTrue(!extensibleCache.getExtensionPoint().getExtensions().iterator().hasNext());
        return getAllNormalMembers(cache);
    });
}
Also used : Extensible(org.apache.geode.internal.cache.extension.Extensible) InternalCache(org.apache.geode.internal.cache.InternalCache) Properties(java.util.Properties) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) File(java.io.File) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 37 with Cache

use of org.apache.geode.cache.Cache in project geode by apache.

the class DataCommandsOverHttpDistributedTest method setupTestRebalanceForEntireDS.

void setupTestRebalanceForEntireDS() {
    final VM vm1 = Host.getHost(0).getVM(1);
    final VM vm2 = Host.getHost(0).getVM(2);
    setUpJmxManagerOnVm0ThenConnect(null);
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            // no need to close cache as it will be closed as part of teardown2
            Cache cache = getCache();
            RegionFactory<Integer, Integer> dataRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
            Region region = dataRegionFactory.create(REBALANCE_REGION_NAME);
            for (int i = 0; i < 10; i++) {
                region.put("key" + (i + 200), "value" + (i + 200));
            }
            region = dataRegionFactory.create(REBALANCE_REGION_NAME + "Another1");
            for (int i = 0; i < 100; i++) {
                region.put("key" + (i + 200), "value" + (i + 200));
            }
        }
    });
    vm2.invoke(new SerializableRunnable() {

        public void run() {
            // no need to close cache as it will be closed as part of teardown2
            Cache cache = getCache();
            RegionFactory<Integer, Integer> dataRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
            Region region = dataRegionFactory.create(REBALANCE_REGION_NAME);
            for (int i = 0; i < 100; i++) {
                region.put("key" + (i + 400), "value" + (i + 400));
            }
            region = dataRegionFactory.create(REBALANCE_REGION_NAME + "Another2");
            for (int i = 0; i < 10; i++) {
                region.put("key" + (i + 200), "value" + (i + 200));
            }
        }
    });
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache)

Example 38 with Cache

use of org.apache.geode.cache.Cache in project geode by apache.

the class WANManagementDUnitTest method checkSenderNavigationAPIS.

@SuppressWarnings("serial")
protected void checkSenderNavigationAPIS(final VM vm, final DistributedMember senderMember) {
    SerializableRunnable checkNavigationAPIS = new SerializableRunnable("Check Sender Navigation APIs") {

        public void run() {
            Cache cache = GemFireCacheImpl.getInstance();
            ManagementService service = ManagementService.getManagementService(cache);
            DistributedSystemMXBean bean = service.getDistributedSystemMXBean();
            ObjectName expectedName = service.getGatewaySenderMBeanName(senderMember, "pn");
            try {
                ObjectName actualName = bean.fetchGatewaySenderObjectName(senderMember.getId(), "pn");
                assertEquals(expectedName, actualName);
            } catch (Exception e) {
                fail("Sender Navigation Failed " + e);
            }
            assertEquals(2, bean.listGatewaySenderObjectNames().length);
            try {
                assertEquals(1, bean.listGatewaySenderObjectNames(senderMember.getId()).length);
            } catch (Exception e) {
                fail("Sender Navigation Failed " + e);
            }
        }
    };
    vm.invoke(checkNavigationAPIS);
}
Also used : SystemManagementService(org.apache.geode.management.internal.SystemManagementService) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Cache(org.apache.geode.cache.Cache) ObjectName(javax.management.ObjectName)

Example 39 with Cache

use of org.apache.geode.cache.Cache in project geode by apache.

the class TestRemoteClusterDUnitTest method checkReceiverMBean.

/**
   * Checks whether a GatewayReceiverMBean is created or not
   * 
   * @param vm reference to VM
   */
@SuppressWarnings("serial")
protected void checkReceiverMBean(final VM vm) {
    SerializableRunnable checkMBean = new SerializableRunnable("Check Receiver MBean") {

        public void run() {
            Cache cache = GemFireCacheImpl.getInstance();
            ManagementService service = ManagementService.getManagementService(cache);
            GatewayReceiverMXBean bean = service.getLocalGatewayReceiverMXBean();
            assertNotNull(bean);
        }
    };
    vm.invoke(checkMBean);
}
Also used : GatewayReceiverMXBean(org.apache.geode.management.GatewayReceiverMXBean) ManagementService(org.apache.geode.management.ManagementService) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Cache(org.apache.geode.cache.Cache)

Example 40 with Cache

use of org.apache.geode.cache.Cache in project geode by apache.

the class TestRemoteClusterDUnitTest method stopGatewaySender.

/**
   * stops a gateway sender
   * 
   * @param vm reference to VM
   */
@SuppressWarnings("serial")
protected void stopGatewaySender(final VM vm) {
    SerializableRunnable stopGatewaySender = new SerializableRunnable("Stop Gateway Sender") {

        public void run() {
            Cache cache = GemFireCacheImpl.getInstance();
            ManagementService service = ManagementService.getManagementService(cache);
            GatewaySenderMXBean bean = service.getLocalGatewaySenderMXBean("pn");
            assertNotNull(bean);
            bean.stop();
            assertFalse(bean.isRunning());
        }
    };
    vm.invoke(stopGatewaySender);
}
Also used : ManagementService(org.apache.geode.management.ManagementService) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) GatewaySenderMXBean(org.apache.geode.management.GatewaySenderMXBean) Cache(org.apache.geode.cache.Cache)

Aggregations

Cache (org.apache.geode.cache.Cache)1044 Region (org.apache.geode.cache.Region)478 Test (org.junit.Test)476 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)292 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)277 VM (org.apache.geode.test.dunit.VM)264 Host (org.apache.geode.test.dunit.Host)230 AttributesFactory (org.apache.geode.cache.AttributesFactory)229 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)177 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)176 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)164 LocalRegion (org.apache.geode.internal.cache.LocalRegion)153 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)123 ClientCache (org.apache.geode.cache.client.ClientCache)117 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)112 Properties (java.util.Properties)101 CacheException (org.apache.geode.cache.CacheException)101 RegionAttributes (org.apache.geode.cache.RegionAttributes)99 QueryService (org.apache.geode.cache.query.QueryService)95 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)93