示例#1
0
  public void testDefensiveCopyOfData() {

    Node<Object, Object> rootNode = cache.getRoot();

    rootNode.put("key", "value");
    Map<Object, Object> data = rootNode.getData();
    Set<Object> keys = rootNode.getKeys();

    assert keys.size() == 1;
    assert keys.contains("key");

    assert data.size() == 1;
    assert data.containsKey("key");

    // now change stuff.

    rootNode.put("key2", "value2");

    // assert that the collections we initially got have not changed.
    assert keys.size() == 1;
    assert keys.contains("key");

    assert data.size() == 1;
    assert data.containsKey("key");
  }
示例#2
0
  public void testClearingData() {

    Node<Object, Object> rootNode = cache.getRoot();

    rootNode.put("k", "v");
    rootNode.put("k2", "v2");
    assertEquals(2, rootNode.getKeys().size());
    rootNode.clearData();
    assertEquals(0, rootNode.getKeys().size());
    assertTrue(rootNode.getData().isEmpty());
  }
示例#3
0
  public void testClearingDataTx() throws Exception {

    Node<Object, Object> rootNode = cache.getRoot();

    tm.begin();
    rootNode.put("k", "v");
    rootNode.put("k2", "v2");
    assertEquals(2, rootNode.getKeys().size());
    rootNode.clearData();
    assertEquals(0, rootNode.getKeys().size());
    assertTrue(rootNode.getData().isEmpty());
    tm.commit();
    assertTrue(rootNode.getData().isEmpty());
  }
示例#4
0
  public void testAddingData() {
    Node<Object, Object> rootNode = cache.getRoot();
    Node<Object, Object> nodeA = rootNode.addChild(A);
    nodeA.put("key", "value");

    assertEquals("value", nodeA.get("key"));
  }
示例#5
0
  public void testAddingDataTx() throws Exception {
    Node<Object, Object> rootNode = cache.getRoot();
    tm.begin();
    Node<Object, Object> nodeA = rootNode.addChild(A);
    nodeA.put("key", "value");

    assertEquals("value", nodeA.get("key"));
    tm.commit();
  }
示例#6
0
 @Test
 public void testCacheManager() {
   ConfigurationBuilder builder = new ConfigurationBuilder();
   builder.transaction().invocationBatching().enable();
   EmbeddedCacheManager cm = new DefaultCacheManager(builder.build());
   Cache<String, String> cache = cm.getCache();
   TreeCacheFactory tcf = new TreeCacheFactory();
   TreeCache<String, String> tree = tcf.createTreeCache(cache);
   Fqn leafFqn = Fqn.fromElements("branch", "leaf");
   Node<String, String> leaf = tree.getRoot().addChild(leafFqn);
   leaf.put("fruit", "orange");
   cm.stop();
 }
示例#7
0
  public void testOverwritingDataTx() throws Exception {
    Node<Object, Object> rootNode = cache.getRoot();

    Node<Object, Object> nodeA = rootNode.addChild(A);
    nodeA.put("key", "value");
    assertEquals("value", nodeA.get("key"));
    tm.begin();
    rootNode.removeChild(A);
    cache.put(A, "k2", "v2");
    tm.commit();
    assertNull(nodeA.get("key"));
    assertEquals("v2", nodeA.get("k2"));
  }
  /**
   * root -productFiles -merchant-id PRODUCT-ID(key) -> CacheAttribute(value) - image 1 - image 2 -
   * image 3
   */
  @Override
  public void addProductImage(ProductImage productImage, ImageContentFile contentImage)
      throws ServiceException {

    if (cacheManager.getTreeCache() == null) {
      throw new ServiceException(
          "CmsImageFileManagerInfinispan has a null cacheManager.getTreeCache()");
    }

    try {

      // node
      StringBuilder nodePath = new StringBuilder();
      nodePath
          .append(productImage.getProduct().getMerchantStore().getCode())
          .append(Constants.SLASH)
          .append(productImage.getProduct().getSku())
          .append(Constants.SLASH);

      if (contentImage.getFileContentType().name().equals(FileContentType.PRODUCT.name())) {
        nodePath.append(SMALL);
      } else if (contentImage
          .getFileContentType()
          .name()
          .equals(FileContentType.PRODUCTLG.name())) {
        nodePath.append(LARGE);
      }

      Node<String, Object> productNode = this.getNode(nodePath.toString());

      InputStream isFile = contentImage.getFile();

      ByteArrayOutputStream output = new ByteArrayOutputStream();
      IOUtils.copy(isFile, output);

      // object for a given product containing all images
      productNode.put(contentImage.getFileName(), output.toByteArray());

    } catch (Exception e) {

      throw new ServiceException(e);
    }
  }
示例#9
0
  public void testImmutabilityOfData() {

    Node<Object, Object> rootNode = cache.getRoot();

    rootNode.put("key", "value");
    Map<Object, Object> m = rootNode.getData();
    try {
      m.put("x", "y");
      fail("Map should be immutable!!");
    } catch (Exception e) {
      // expected
    }

    try {
      rootNode.getKeys().add(new Object());
      fail("Key set should be immutable");
    } catch (Exception e) {
      // expected
    }
  }
示例#10
0
  public void testBasicOperation()
      throws SystemException, NotSupportedException, HeuristicMixedException,
          HeuristicRollbackException, RollbackException {
    assertClusterSize("Should only be 2  caches in the cluster!!!", 2);

    Fqn f = Fqn.fromString("/test/data");
    String k = "key", v = "value";

    assertNull("Should be null", cache1.getRoot().getChild(f));
    assertNull("Should be null", cache2.getRoot().getChild(f));

    Node<Object, Object> node = cache1.getRoot().addChild(f);

    assertNotNull("Should not be null", node);

    TransactionManager tm = beginTransaction(cache1.getCache());
    node.put(k, v);
    tm.commit();

    assertEquals(v, node.get(k));
    assertEquals(v, cache1.get(f, k));
    assertEquals("Should have replicated", v, cache2.get(f, k));
  }