Package ro.isdc.wro.cache

Examples of ro.isdc.wro.cache.CacheKey


  @Test
  public void shouldCreateValidCacheKeyWhenRequestContainsAllRequiredInfo() {
    when(mockGroupExtractor.isMinimized(mockRequest)).thenReturn(true);
    when(mockGroupExtractor.getGroupName(mockRequest)).thenReturn("g1");
    when(mockGroupExtractor.getResourceType(mockRequest)).thenReturn(ResourceType.CSS);
    assertEquals(new CacheKey("g1", ResourceType.CSS, true), victim.create(mockRequest));
  }
View Full Code Here


      throws IOException {
    when(mockGroupExtractor.isMinimized(mockRequest)).thenReturn(true);
    when(mockGroupExtractor.getGroupName(mockRequest)).thenReturn("g1");
    when(mockGroupExtractor.getResourceType(mockRequest)).thenReturn(ResourceType.CSS);
    Context.get().getConfig().setMinimizeEnabled(false);
    assertEquals(new CacheKey("g1", ResourceType.CSS, false), victim.create(mockRequest));
  }
View Full Code Here

      @Override
      String generateRandomKey() {
        return authKey;
      }
    };
    final CacheKey expected = new CacheKey("group", ResourceType.CSS);
    new InjectorBuilder(new BaseWroManagerFactory()).setResourceWatcher(resourceWatcher).build().inject(victim);
    when(request.getParameter(Mockito.eq(ResourceWatcherRequestHandler.PATH_API))).thenReturn(
        ResourceWatcherRequestHandler.PATH_HANDLER);
    when(request.getParameter(Mockito.eq(ResourceWatcherRequestHandler.PARAM_GROUP_NAME))).thenReturn(
        expected.getGroupName());
    when(request.getParameter(Mockito.eq(ResourceWatcherRequestHandler.PARAM_RESOURCE_TYPE))).thenReturn(
        expected.getType().name());
    when(request.getParameter(Mockito.eq(ResourceWatcherRequestHandler.PARAM_AUTH_KEY))).thenReturn(authKey);
    when(request.getRequestURI()).thenReturn("/style.css?wroAPI=resourceWatcher");
    assertTrue(victim.accept(request));

    victim.handle(request, response);
View Full Code Here

  }

  @Test
  public void testLruCache() throws IOException {
    final HashStrategy builder = new CRC32HashStrategy();
    final CacheKey key1 = new CacheKey("testGroup01", ResourceType.JS, false);
    final CacheKey key2 = new CacheKey("testGroup02", ResourceType.CSS, false);
    final CacheKey key3 = new CacheKey("testGroup03", ResourceType.JS, false);
    final CacheKey key4 = new CacheKey("testGroup04", ResourceType.CSS, false);

    final String content = "var foo = 'Hello World';";
    final String hash = builder.getHash(new ByteArrayInputStream(content.getBytes()));

    cache.put(key1, CacheValue.valueOf(content, hash));
View Full Code Here

  }

  @Test
  public void shouldNotCheckForChangesWhenResourceWatcherPeriodIsNotSet()
      throws Exception {
    final CacheKey key = new CacheKey("g1", ResourceType.JS, true);
    victim.get(key);
    victim.get(key);
    verify(mockResourceWatcher, never()).check(key);
  }
View Full Code Here

  public void shouldCheckOnlyAfterTimeout()
      throws Exception {
    final long updatePeriod = 10;
    final long delta = 5;
    Context.get().getConfig().setResourceWatcherUpdatePeriod(updatePeriod);
    final CacheKey key = new CacheKey("g1", ResourceType.JS, true);
    when(mockResourceWatcher.tryAsyncCheck(Mockito.eq(key))).thenReturn(true);
    final long start = System.currentTimeMillis();
    do {
      victim.get(key);
    } while (System.currentTimeMillis() - start < updatePeriod - delta);
View Full Code Here

  public void shouldCheckDifferentGroups()
      throws Exception {
    final long updatePeriod = 10;
    final long delta = 4;
    Context.get().getConfig().setResourceWatcherUpdatePeriod(updatePeriod);
    final CacheKey key1 = new CacheKey(GROUP_NAME, ResourceType.JS, true);
    final CacheKey key2 = new CacheKey(GROUP_NAME, ResourceType.CSS, true);
    final long start = System.currentTimeMillis();
    victim.get(key1);
    Thread.sleep(updatePeriod);
    do {
      victim.get(key1);
View Full Code Here

  }

  @Test
  public void shouldNotWatchForChangeUnlessCheckCompleted() {
    Context.get().getConfig().setResourceWatcherUpdatePeriod(100);
    final CacheKey key = new CacheKey(GROUP_NAME, ResourceType.JS, true);

    when(mockResourceWatcher.tryAsyncCheck(Mockito.eq(key))).thenReturn(false);
    victim.get(key);
    assertFalse(victim.wasCheckedForChange(key));
View Full Code Here

    resourceWatcher.check(retrieveCacheKey(request));
    updateAuthorizationKey();
  }

  private CacheKey retrieveCacheKey(final HttpServletRequest request) {
    CacheKey cacheKey = null;
    final String resourceTypeAsString = request.getParameter(PARAM_RESOURCE_TYPE);
    final String groupName = request.getParameter(PARAM_GROUP_NAME);
    try {
      final ResourceType resourceType = ResourceType.get(resourceTypeAsString);
      isTrue(groupName != null);
      if (groupName != null) {
        LOG.debug("groupName={}, resourceType={}", groupName, resourceType);
        cacheKey = new CacheKey(groupName, resourceType);
      }
    } catch (final IllegalArgumentException e) {
      LOG.debug("groupName={}, resourceType={}", groupName, resourceTypeAsString);
      throw WroRuntimeException.wrap(e, "Cannot retrieve cacheKey from the request");
    }
View Full Code Here

   * @return a path to the resource with the fingerprint encoded as a folder name.
   */
  public final String encodeVersionIntoGroupPath(final String groupName, final ResourceType resourceType,
      final boolean minimize) {
    // TODO use CacheKeyFactory
    final CacheKey key = new CacheKey(groupName, resourceType, minimize);
    final CacheValue cacheValue = cacheStrategy.get(key);
    final String groupUrl = groupExtractor.encodeGroupUrl(groupName, resourceType, minimize);
    // encode the fingerprint of the resource into the resource path
    return formatVersionedResource(cacheValue.getHash(), groupUrl);
  }
View Full Code Here

TOP

Related Classes of ro.isdc.wro.cache.CacheKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.