Search in sources :

Example 6 with Extensible

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

the class DestroyMockCacheExtensionFunction method execute.

@Override
public void execute(FunctionContext context) {
    final Cache cache = CacheFactory.getAnyInstance();
    if (!(cache instanceof Extensible)) {
        throw new FunctionException("Not extensible cache.");
    }
    @SuppressWarnings("unchecked") final Extensible<Cache> extensible = (Extensible<Cache>) cache;
    for (Extension<Cache> extension : extensible.getExtensionPoint().getExtensions()) {
        if (extension instanceof MockCacheExtension) {
            extensible.getExtensionPoint().removeExtension(extension);
            break;
        }
    }
    final XmlEntity xmlEntity = XmlEntity.builder().withType(ELEMENT_CACHE).withNamespace(PREFIX, NAMESPACE).build();
    final ResultSender<Object> resultSender = context.getResultSender();
    final String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
    resultSender.lastResult(new CliFunctionResult(memberNameOrId, xmlEntity, CliStrings.format("Mock cache extension destroyed on \"{0}\"", new Object[] { memberNameOrId })));
}
Also used : XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) Extensible(org.apache.geode.internal.cache.extension.Extensible) FunctionException(org.apache.geode.cache.execute.FunctionException) Cache(org.apache.geode.cache.Cache)

Example 7 with Extensible

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

the class DestroyMockRegionExtensionFunction method execute.

@Override
public void execute(FunctionContext context) {
    final Cache cache = CacheFactory.getAnyInstance();
    final Region<?, ?> region = cache.getRegion((String) ((Object[]) context.getArguments())[0]);
    if (!(region instanceof Extensible)) {
        throw new FunctionException("Not extensible region.");
    }
    @SuppressWarnings("unchecked") final Extensible<Region<?, ?>> extensible = (Extensible<Region<?, ?>>) region;
    for (Extension<Region<?, ?>> extension : extensible.getExtensionPoint().getExtensions()) {
        if (extension instanceof MockRegionExtension) {
            extensible.getExtensionPoint().removeExtension(extension);
            break;
        }
    }
    XmlEntity xmlEntity = new XmlEntity(CacheXml.REGION, "name", region.getName());
    final ResultSender<Object> resultSender = context.getResultSender();
    final String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
    resultSender.lastResult(new CliFunctionResult(memberNameOrId, xmlEntity, CliStrings.format("Mock region extension \"{0}\" destroyed on \"{1}\"", new Object[] { region.getFullPath(), memberNameOrId })));
}
Also used : Extensible(org.apache.geode.internal.cache.extension.Extensible) FunctionException(org.apache.geode.cache.execute.FunctionException) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache)

Example 8 with Extensible

use of org.apache.geode.internal.cache.extension.Extensible 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 9 with Extensible

use of org.apache.geode.internal.cache.extension.Extensible 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 10 with Extensible

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

the class CacheXml81DUnitTest method testLocatorInException.

/**
   * Test {@link Locator} is used in {@link SAXParseException}. Exercises
   * {@link XmlParser#setDocumentLocator(Locator)}
   * 
   * @since GemFire 8.2
   */
@Test
public void testLocatorInException() throws Exception {
    final String regionName = "testRegionExtension";
    final CacheCreation cache = new CacheCreation();
    final RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
    @SuppressWarnings("unchecked") Extensible<Region<?, ?>> region = (Extensible<Region<?, ?>>) cache.createRegion(regionName, attrs);
    final MockRegionExtension extension = new MockRegionExtension("exception");
    region.getExtensionPoint().addExtension(extension);
    assertEquals(0, extension.beforeCreateCounter.get());
    assertEquals(0, extension.onCreateCounter.get());
    assertEquals(0, extension.getXmlGeneratorCounter.get());
    IgnoredException.addIgnoredException("While reading Cache XML file");
    try {
        testXml(cache);
        fail("Excepted CacheXmlException");
    } catch (final CacheXmlException e) {
        if (e.getCause() instanceof SAXParseException) {
            assertTrue(((SAXParseException) e.getCause()).getLineNumber() > 0);
            assertTrue(((SAXParseException) e.getCause()).getColumnNumber() > 0);
            assertEquals("Value is 'exception'.", e.getCause().getMessage());
        }
    }
}
Also used : Extensible(org.apache.geode.internal.cache.extension.Extensible) CacheXmlException(org.apache.geode.cache.CacheXmlException) SAXParseException(org.xml.sax.SAXParseException) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) Region(org.apache.geode.cache.Region) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) MockRegionExtension(org.apache.geode.internal.cache.extension.mock.MockRegionExtension) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

Extensible (org.apache.geode.internal.cache.extension.Extensible)14 Cache (org.apache.geode.cache.Cache)9 Region (org.apache.geode.cache.Region)9 FunctionException (org.apache.geode.cache.execute.FunctionException)6 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)6 XmlEntity (org.apache.geode.management.internal.configuration.domain.XmlEntity)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 Test (org.junit.Test)5 File (java.io.File)3 Iterator (java.util.Iterator)3 InternalCache (org.apache.geode.internal.cache.InternalCache)3 LocalRegion (org.apache.geode.internal.cache.LocalRegion)3 MockRegionExtension (org.apache.geode.internal.cache.extension.mock.MockRegionExtension)3 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)3 Map (java.util.Map)2 Properties (java.util.Properties)2 TreeSet (java.util.TreeSet)2 AbstractRegion (org.apache.geode.internal.cache.AbstractRegion)2 DiskWriteAttributesImpl (org.apache.geode.internal.cache.DiskWriteAttributesImpl)2 PartitionAttributesImpl (org.apache.geode.internal.cache.PartitionAttributesImpl)2