@Test
  public void shouldRetrieveLowLevelCacheEntryForDefaultBinaryStore() {
    final BinaryKey key = new BinaryKey("key-123");
    when(mockStoreFunc.apply(mockRepo)).thenReturn(mockStore);

    final LowLevelStorageService testObj = spy(new LowLevelStorageService());
    testObj.setRepository(mockRepo);
    testObj.setGetBinaryStore(mockStoreFunc);
    testObj.getLowLevelCacheEntries(key);
    verify(testObj, times(1)).getLowLevelCacheEntriesFromStore(mockStore, key);
  }
  @Test
  public void shouldReturnAnEmptySetForMissingBinaryStore() {

    when(mockStoreFunc.apply(mockRepo)).thenReturn(null);

    final LowLevelStorageService testObj = new LowLevelStorageService();
    testObj.setGetBinaryStore(mockStoreFunc);
    final Set<LowLevelCacheEntry> entries =
        testObj.getLowLevelCacheEntries(new BinaryKey("key-123"));

    assertEquals(0, entries.size());
  }
  @Test
  public void testGetBinaryBlobs() throws RepositoryException {

    when(mockNode.getProperty(JCR_DATA)).thenReturn(mockProperty);
    when(mockStore.toString()).thenReturn("foo");
    when(mockKeyFunc.apply(mockProperty)).thenReturn(mockKey);
    when(mockStoreFunc.apply(mockRepo)).thenReturn(mockStore);
    final LowLevelStorageService testObj = new LowLevelStorageService();
    testObj.setGetBinaryStore(mockStoreFunc);
    testObj.setGetBinaryKey(mockKeyFunc);
    testObj.setRepository(mockRepo);
    final Set<LowLevelCacheEntry> actual = testObj.getLowLevelCacheEntries(mockNode);
    assertEquals("/foo", actual.iterator().next().getExternalIdentifier());
  }
  @Test
  public void testTransformBinaryBlobs() throws RepositoryException {

    when(mockNode.getProperty(JcrConstants.JCR_DATA)).thenReturn(mockProperty);
    when(mockStore.toString()).thenReturn("foo");
    when(mockKeyFunc.apply(mockProperty)).thenReturn(mockKey);
    when(mockStoreFunc.apply(mockRepo)).thenReturn(mockStore);
    final LowLevelStorageService testObj = new LowLevelStorageService();
    testObj.setGetBinaryStore(mockStoreFunc);
    testObj.setGetBinaryKey(mockKeyFunc);
    testObj.setRepository(mockRepo);
    @SuppressWarnings("unchecked")
    final Function<LowLevelCacheEntry, String> testFunc = mock(Function.class);
    when(testFunc.apply(any(LowLevelCacheEntry.class))).thenReturn("bar");
    final Collection<String> actual = testObj.transformLowLevelCacheEntries(mockNode, testFunc);
    assertEquals("bar", actual.iterator().next());
    verify(testFunc).apply(any(LowLevelCacheEntry.class));
  }
예제 #5
0
  /**
   * Extract the BinaryStore out of Modeshape (infinspan, jdbc, file, transient, etc)
   *
   * @return
   */
  @Override
  public Map<String, String> apply(final Repository input) {
    checkNotNull(input, "null cannot have a BinaryStore!");

    final Map<String, String> result = new LinkedHashMap<>();
    final BinaryStore store = getBinaryStore.apply(input);

    if (!(store instanceof InfinispanBinaryStore)) {
      return result;
    }

    final InfinispanBinaryStore ispnStore = (InfinispanBinaryStore) store;

    final List<Cache<?, ?>> caches = ispnStore.getCaches();
    final DefaultCacheManager cm = (DefaultCacheManager) caches.get(0).getCacheManager();

    if (cm == null) {
      LOGGER.debug("Could not get cluster configuration information");
      return result;
    }

    final int nodeView;

    if (cm.getTransport() != null) {
      nodeView = cm.getTransport().getViewId() + 1;
    } else {
      nodeView = UNKNOWN_NODE_VIEW;
    }

    result.put(CLUSTER_NAME, cm.getClusterName());
    result.put(
        CACHE_MODE, cm.getCache().getCacheConfiguration().clustering().cacheMode().toString());
    result.put(NODE_ADDRESS, cm.getNodeAddress());
    result.put(PHYSICAL_ADDRESS, cm.getPhysicalAddresses());
    result.put(NODE_VIEW, nodeView == UNKNOWN_NODE_VIEW ? "Unknown" : String.valueOf(nodeView));
    result.put(CLUSTER_SIZE, String.valueOf(cm.getClusterSize()));
    result.put(CLUSTER_MEMBERS, cm.getClusterMembers());
    return result;
  }