Search in sources :

Example 1 with MockCacheExtension

use of org.apache.geode.internal.cache.extension.mock.MockCacheExtension in project geode by apache.

the class ClusterConfigurationDUnitTest method testCreateExtensions.

/**
   * Tests for {@link Extension}, {@link Extensible}, {@link XmlParser}, {@link XmlGenerator},
   * {@link XmlEntity} as it applies to Extensions. Asserts that Mock Extension is created and
   * altered on region and cache.
   * 
   * @since GemFire 8.1
   */
// GEODE-1334
@Category(FlakyTest.class)
@Test
public void testCreateExtensions() throws Exception {
    Object[] result = setup();
    final int locatorPort = (Integer) result[0];
    createRegion(REPLICATE_REGION, RegionShortcut.REPLICATE, null);
    createMockRegionExtension(REPLICATE_REGION, "value1");
    alterMockRegionExtension(REPLICATE_REGION, "value2");
    createMockCacheExtension("value1");
    alterMockCacheExtension("value2");
    // Start a new member which receives the shared configuration
    // Verify the config creation on this member
    final String newMemberWorkDir = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + newMember;
    VM newMember = getHost(0).getVM(2);
    newMember.invoke(() -> {
        Properties localProps = new Properties();
        File workingDir = new File(newMemberWorkDir);
        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 MockRegionExtension // should only be one region extension
        mockRegionExtension = (MockRegionExtension) ((Extensible<Region<?, ?>>) region1).getExtensionPoint().getExtensions().iterator().next();
        assertNotNull(mockRegionExtension);
        assertEquals(1, mockRegionExtension.beforeCreateCounter.get());
        assertEquals(1, mockRegionExtension.onCreateCounter.get());
        assertEquals("value2", mockRegionExtension.getValue());
        // MockCacheExtension verification
        @SuppressWarnings("unchecked") final MockCacheExtension // should only be one cache extension
        mockCacheExtension = (MockCacheExtension) ((Extensible<Cache>) cache).getExtensionPoint().getExtensions().iterator().next();
        assertNotNull(mockCacheExtension);
        assertEquals(1, mockCacheExtension.beforeCreateCounter.get());
        assertEquals(1, mockCacheExtension.onCreateCounter.get());
        assertEquals("value2", mockCacheExtension.getValue());
        return getAllNormalMembers(cache);
    });
}
Also used : Extensible(org.apache.geode.internal.cache.extension.Extensible) InternalCache(org.apache.geode.internal.cache.InternalCache) Properties(java.util.Properties) MockRegionExtension(org.apache.geode.internal.cache.extension.mock.MockRegionExtension) VM(org.apache.geode.test.dunit.VM) MockCacheExtension(org.apache.geode.internal.cache.extension.mock.MockCacheExtension) File(java.io.File) 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 2 with MockCacheExtension

use of org.apache.geode.internal.cache.extension.mock.MockCacheExtension in project geode by apache.

the class CacheXml81DUnitTest method testCacheExtension.

/**
   * Test extensions to <code>cache</code> element.
   * 
   * @since GemFire 8.1
   */
@Test
public void testCacheExtension() throws Exception {
    final CacheCreation cache = new CacheCreation();
    final MockCacheExtension extension = new MockCacheExtension("testCacheExtension");
    cache.getExtensionPoint().addExtension(extension);
    assertEquals(0, extension.beforeCreateCounter.get());
    assertEquals(0, extension.onCreateCounter.get());
    assertEquals(0, extension.getXmlGeneratorCounter.get());
    testXml(cache);
    assertEquals(0, extension.beforeCreateCounter.get());
    assertEquals(0, extension.onCreateCounter.get());
    assertEquals(1, extension.getXmlGeneratorCounter.get());
    @SuppressWarnings("unchecked") final Extensible<Cache> c = (Extensible<Cache>) getCache();
    assertNotNull(c);
    final MockCacheExtension m = (MockCacheExtension) c.getExtensionPoint().getExtensions().iterator().next();
    assertNotNull(m);
    assertEquals(1, m.beforeCreateCounter.get());
    assertEquals(1, m.onCreateCounter.get());
    assertEquals(0, m.getXmlGeneratorCounter.get());
}
Also used : Extensible(org.apache.geode.internal.cache.extension.Extensible) MockCacheExtension(org.apache.geode.internal.cache.extension.mock.MockCacheExtension) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

Extensible (org.apache.geode.internal.cache.extension.Extensible)2 MockCacheExtension (org.apache.geode.internal.cache.extension.mock.MockCacheExtension)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2 Test (org.junit.Test)2 File (java.io.File)1 Properties (java.util.Properties)1 Cache (org.apache.geode.cache.Cache)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1 MockRegionExtension (org.apache.geode.internal.cache.extension.mock.MockRegionExtension)1 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)1 VM (org.apache.geode.test.dunit.VM)1 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)1 Category (org.junit.experimental.categories.Category)1