/tree/src/test/java/org/infinispan/api/tree/FlagTest.java

https://github.com/an1310/infinispan · Java · 65 lines · 54 code · 6 blank · 5 comment · 0 complexity · 3298b27067610ed943cb656bfa963a73 MD5 · raw file

  1. package org.infinispan.api.tree;
  2. import org.infinispan.AdvancedCache;
  3. import org.infinispan.Cache;
  4. import org.infinispan.configuration.cache.CacheMode;
  5. import org.infinispan.configuration.cache.ConfigurationBuilder;
  6. import org.infinispan.context.Flag;
  7. import org.infinispan.test.MultipleCacheManagersTest;
  8. import org.infinispan.tree.Fqn;
  9. import org.infinispan.tree.TreeCache;
  10. import org.infinispan.tree.TreeCacheFactory;
  11. import org.infinispan.util.logging.Log;
  12. import org.infinispan.util.logging.LogFactory;
  13. import org.testng.annotations.Test;
  14. /**
  15. * @author <a href="mailto:konstantin.kuzmin@db.com">Konstantin Kuzmin</a>
  16. * @author Galder Zamarreño
  17. * @since 4.2
  18. */
  19. @Test(groups = "functional", testName = "api.tree.FlagTest")
  20. public class FlagTest extends MultipleCacheManagersTest {
  21. private Cache<String, String> cache1, cache2;
  22. private TreeCache<String, String> treeCache1, treeCache2;
  23. private static final String KEY = "key";
  24. private static final Log log = LogFactory.getLog(FlagTest.class);
  25. @Override
  26. protected void createCacheManagers() throws Throwable {
  27. ConfigurationBuilder cb = getDefaultClusteredCacheConfig(CacheMode.INVALIDATION_SYNC, true);
  28. cb.invocationBatching().enable();
  29. createClusteredCaches(2, "invalidatedFlagCache", cb);
  30. cache1 = cache(0, "invalidatedFlagCache");
  31. cache2 = cache(1, "invalidatedFlagCache");
  32. TreeCacheFactory tcf = new TreeCacheFactory();
  33. treeCache1 = tcf.createTreeCache(cache1);
  34. treeCache2 = tcf.createTreeCache(cache2);
  35. }
  36. public void testTreeCacheLocalPut() throws Exception {
  37. final Fqn fqn = Fqn.fromElements("TEST");
  38. treeCache1.put(fqn, KEY, "1", Flag.CACHE_MODE_LOCAL);
  39. treeCache2.put(fqn, KEY, "2", Flag.CACHE_MODE_LOCAL);
  40. assert "2".equals(treeCache2.get(fqn, KEY)) : "treeCache2 was updated locally";
  41. assert "1".equals(treeCache1.get(fqn, KEY)) : "treeCache1 should not be invalidated in case of LOCAL put in treeCache2";
  42. String fqnString = "fqnAsString";
  43. treeCache1.put(fqnString, KEY, "3", Flag.CACHE_MODE_LOCAL);
  44. treeCache2.put(fqnString, KEY, "4", Flag.CACHE_MODE_LOCAL);
  45. assert "4".equals(treeCache2.get(fqnString, KEY)) : "treeCache2 was updated locally";
  46. assert "3".equals(treeCache1.get(fqnString, KEY)) : "treeCache1 should not be invalidated in case of LOCAL put in treeCache2";
  47. }
  48. public void testWithFlags() {
  49. AdvancedCache<String, String> localCache1 = cache1.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL);
  50. AdvancedCache<String, String> localCache2 = cache2.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL);
  51. TreeCache<String, String> treeCache1 = new TreeCacheFactory().createTreeCache(localCache1);
  52. TreeCache<String, String> treeCache2 = new TreeCacheFactory().createTreeCache(localCache2);
  53. final Fqn fqn = Fqn.fromElements("TEST_WITH_FLAGS");
  54. treeCache1.put(fqn, KEY, "1");
  55. treeCache2.put(fqn, KEY, "2");
  56. assert "2".equals(treeCache2.get(fqn, KEY)) : "treeCache2 was updated locally";
  57. assert "1".equals(treeCache1.get(fqn, KEY)) : "treeCache1 should not be invalidated in case of LOCAL put in treeCache2";
  58. }
  59. }