Search in sources :

Example 1 with ResourceEvent

use of org.apache.geode.internal.cache.control.ResourceEvent in project geode by apache.

the class ResourceManagerDUnitTest method testResourceManagerBasics.

/**
   * Creates a cache in the controller and exercises all methods on the ResourceManager without
   * having any partitioned regions defined.
   */
@Test
public void testResourceManagerBasics() {
    Cache cache = getCache();
    // verify that getResourceManager works
    ResourceManager manager = cache.getResourceManager();
    assertNotNull(manager);
    // verify that getPartitionedRegionDetails returns empty set
    Set<PartitionRegionInfo> detailsSet = PartitionRegionHelper.getPartitionRegionInfo(cache);
    assertNotNull(detailsSet);
    assertEquals(Collections.emptySet(), detailsSet);
    ResourceListener listener = new ResourceListener() {

        public void onEvent(ResourceEvent event) {
        }
    };
    InternalResourceManager internalManager = (InternalResourceManager) manager;
    // verify that addResourceListener works
    internalManager.addResourceListener(listener);
    Set<ResourceListener> listeners = internalManager.getResourceListeners(ResourceType.HEAP_MEMORY);
    assertNotNull(listeners);
    assertEquals(1 + SYSTEM_LISTENERS, listeners.size());
    assertTrue(listeners.contains(listener));
    // verify that repeat adds result in only one entry of the listener
    internalManager.addResourceListener(ResourceType.HEAP_MEMORY, listener);
    listeners = internalManager.getResourceListeners(ResourceType.HEAP_MEMORY);
    assertEquals(1 + SYSTEM_LISTENERS, listeners.size());
    // verify that removeResourceListener works
    internalManager.removeResourceListener(listener);
    listeners = internalManager.getResourceListeners(ResourceType.HEAP_MEMORY);
    assertEquals(listeners.size(), SYSTEM_LISTENERS);
}
Also used : ResourceListener(org.apache.geode.internal.cache.control.ResourceListener) ResourceEvent(org.apache.geode.internal.cache.control.ResourceEvent) InternalResourceManager(org.apache.geode.internal.cache.control.InternalResourceManager) ResourceManager(org.apache.geode.cache.control.ResourceManager) PartitionRegionInfo(org.apache.geode.cache.partition.PartitionRegionInfo) Cache(org.apache.geode.cache.Cache) InternalResourceManager(org.apache.geode.internal.cache.control.InternalResourceManager) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

Cache (org.apache.geode.cache.Cache)1 ResourceManager (org.apache.geode.cache.control.ResourceManager)1 PartitionRegionInfo (org.apache.geode.cache.partition.PartitionRegionInfo)1 InternalResourceManager (org.apache.geode.internal.cache.control.InternalResourceManager)1 ResourceEvent (org.apache.geode.internal.cache.control.ResourceEvent)1 ResourceListener (org.apache.geode.internal.cache.control.ResourceListener)1 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)1 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)1 Test (org.junit.Test)1