コード例 #1
0
  public void testToMap() throws Exception {
    Configuration cfg =
        CacheTestUtil.buildConfiguration("test", SharedJBossCacheRegionFactory.class, true, true);
    JBossCacheRegionFactory regionFactory =
        CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());

    Region region =
        createRegion(regionFactory, "test/test", cfg.getProperties(), getCacheDataDescription());

    Map map = region.toMap();
    assertNotNull(map);
    assertEquals(0, map.size());

    putInRegion(region, "key1", "value1");
    putInRegion(region, "key2", "value2");

    map = region.toMap();
    assertNotNull(map);
    assertEquals(2, map.size());
    assertEquals("value1", map.get("key1"));
    assertEquals("value2", map.get("key2"));

    removeFromRegion(region, "key1");

    map = region.toMap();
    assertNotNull(map);
    assertEquals(1, map.size());
    assertEquals("value2", map.get("key2"));
  }
コード例 #2
0
  /**
   * Tests proper handling of region initialization and destruction.
   *
   * @throws Exception
   */
  public void testActivationDeactivation() throws Exception {

    // Set up a cache to monitor affects of starting the region
    Cache remoteCache =
        DefaultCacheFactory.getInstance()
            .createCache(SharedCacheInstanceManager.DEFAULT_CACHE_RESOURCE, false);

    // This test assumes replication; verify that's correct
    assertEquals(
        "Cache is REPL_SYNC", "REPL_SYNC", remoteCache.getConfiguration().getCacheModeString());

    JChannelFactory channelFactory = new JChannelFactory();
    channelFactory.setMultiplexerConfig(SharedCacheInstanceManager.DEF_JGROUPS_RESOURCE);
    remoteCache.getConfiguration().getRuntimeConfig().setMuxChannelFactory(channelFactory);
    remoteCache.start();

    // Make sure we stop the remoteCache
    registerCache(remoteCache);

    Fqn regionFqn = getRegionFqn("test/test", "test");

    assertNull("No region node", remoteCache.getRoot().getChild(regionFqn));

    Configuration cfg =
        CacheTestUtil.buildConfiguration("test", SharedJBossCacheRegionFactory.class, true, true);
    JBossCacheRegionFactory regionFactory =
        CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());

    Region region =
        createRegion(regionFactory, "test/test", cfg.getProperties(), getCacheDataDescription());

    Cache localCache = getJBossCache(regionFactory);

    // This test assumes replication; verify that's correct
    assertEquals(
        "Cache is REPL_SYNC", "REPL_SYNC", localCache.getConfiguration().getCacheModeString());

    // Region creation should not have affected remoteCache

    assertNull("No region node", remoteCache.getRoot().getChild(regionFqn));
    Node regionRoot = localCache.getRoot().getChild(regionFqn);
    assertTrue("Has a node at " + regionFqn, regionRoot != null);
    assertTrue(regionFqn + " is resident", regionRoot.isResident());

    // Confirm region destroy does not affect remote cache

    Option option = new Option();
    option.setCacheModeLocal(true);
    remoteCache.getInvocationContext().setOptionOverrides(option);
    remoteCache.put(regionFqn, "test", "test");

    assertEquals("Put succeeded", "test", remoteCache.get(regionFqn, "test"));
    assertNull("Put was local", localCache.get(regionFqn, "test"));

    region.destroy();

    assertEquals("Remote cache unchanged", "test", remoteCache.get(regionFqn, "test"));
    assertNull("No region node", localCache.getRoot().getChild(regionFqn));
  }