Ejemplo n.º 1
0
  public void testPutData() {

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

    assertTrue(rootNode.getData().isEmpty());

    Map<Object, Object> map = new HashMap<Object, Object>();
    map.put("k1", "v1");
    map.put("k2", "v2");

    rootNode.putAll(map);

    assertEquals(2, rootNode.getData().size());
    assertEquals("v1", rootNode.get("k1"));
    assertEquals("v2", rootNode.get("k2"));

    map.clear();
    map.put("k3", "v3");

    rootNode.putAll(map);
    assertEquals(3, rootNode.getData().size());
    assertEquals("v1", rootNode.get("k1"));
    assertEquals("v2", rootNode.get("k2"));
    assertEquals("v3", rootNode.get("k3"));

    map.clear();
    map.put("k4", "v4");
    map.put("k5", "v5");

    rootNode.replaceAll(map);
    assertEquals(2, rootNode.getData().size());
    assertEquals("v4", rootNode.get("k4"));
    assertEquals("v5", rootNode.get("k5"));
  }
Ejemplo n.º 2
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"));
  }
Ejemplo n.º 3
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"));
  }
Ejemplo n.º 4
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();
  }
  @Override
  public List<OutputContentFile> getImages(
      final String merchantStoreCode, FileContentType imageContentType) throws ServiceException {
    if (cacheManager.getTreeCache() == null) {
      throw new ServiceException(
          "CmsImageFileManagerInfinispan has a null cacheManager.getTreeCache()");
    }
    List<OutputContentFile> images = new ArrayList<OutputContentFile>();
    FileNameMap fileNameMap = URLConnection.getFileNameMap();

    try {

      StringBuilder nodePath = new StringBuilder();
      nodePath.append(merchantStoreCode);

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

      Set<Node<String, Object>> childs = merchantNode.getChildren();

      Iterator<Node<String, Object>> iterator = childs.iterator();
      // TODO image sizes
      while (iterator.hasNext()) {

        Node<String, Object> node = iterator.next();

        for (String key : node.getKeys()) {

          byte[] imageBytes = (byte[]) merchantNode.get(key);

          OutputContentFile contentImage = new OutputContentFile();

          InputStream input = new ByteArrayInputStream(imageBytes);
          ByteArrayOutputStream output = new ByteArrayOutputStream();
          IOUtils.copy(input, output);

          String contentType = fileNameMap.getContentTypeFor(key);

          contentImage.setFile(output);
          contentImage.setMimeType(contentType);
          contentImage.setFileName(key);

          images.add(contentImage);
        }
      }

    } catch (Exception e) {
      throw new ServiceException(e);
    } finally {

    }

    return images;
  }
  private OutputContentFile getProductImage(
      String merchantStoreCode, String productCode, String imageName, String size)
      throws ServiceException {

    if (cacheManager.getTreeCache() == null) {
      throw new ServiceException(
          "CmsImageFileManagerInfinispan has a null cacheManager.getTreeCache()");
    }
    InputStream input = null;
    OutputContentFile contentImage = new OutputContentFile();
    try {

      FileNameMap fileNameMap = URLConnection.getFileNameMap();

      // SMALL by default
      StringBuilder nodePath = new StringBuilder();
      nodePath
          .append(merchantStoreCode)
          .append(Constants.SLASH)
          .append(productCode)
          .append(Constants.SLASH)
          .append(size);

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

      byte[] imageBytes = (byte[]) productNode.get(imageName);

      input = new ByteArrayInputStream(imageBytes);
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      IOUtils.copy(input, output);

      String contentType = fileNameMap.getContentTypeFor(imageName);

      contentImage.setFile(output);
      contentImage.setMimeType(contentType);
      contentImage.setFileName(imageName);

    } catch (Exception e) {
      throw new ServiceException(e);
    } finally {
      if (input != null) {
        try {
          input.close();
        } catch (Exception ignore) {
        }
      }
    }

    return contentImage;
  }
  @Override
  public List<OutputContentFile> getImages(Product product) throws ServiceException {

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

    List<OutputContentFile> images = new ArrayList<OutputContentFile>();

    try {

      FileNameMap fileNameMap = URLConnection.getFileNameMap();
      StringBuilder nodePath = new StringBuilder();
      nodePath.append(product.getMerchantStore().getCode());

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

      if (merchantNode == null) {
        return null;
      }

      for (String key : merchantNode.getKeys()) {

        byte[] imageBytes = (byte[]) merchantNode.get(key);

        OutputContentFile contentImage = new OutputContentFile();

        InputStream input = new ByteArrayInputStream(imageBytes);
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        IOUtils.copy(input, output);

        String contentType = fileNameMap.getContentTypeFor(key);

        contentImage.setFile(output);
        contentImage.setMimeType(contentType);
        contentImage.setFileName(key);

        images.add(contentImage);
      }

    } catch (Exception e) {
      throw new ServiceException(e);
    } finally {

    }

    return images;
  }
Ejemplo n.º 8
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));
  }