@BenchmarkOptions(benchmarkRounds = 1, warmupRounds = 0)
  @Test
  public void validateRetieveItemWithLastAccessUpdateTimeDelay() throws Exception {
    // need to ensure we wait 100 ms
    int wait = 100;

    ((DefaultAttributesHandler) repository.getAttributesHandler()).setLastRequestedResolution(wait);
    Thread.sleep(wait);

    AttributeStorage attributeStorageSpy =
        Mockito.spy(repository.getAttributesHandler().getAttributeStorage());
    repository.getAttributesHandler().setAttributeStorage(attributeStorageSpy);

    ResourceStoreRequest resourceRequest = new ResourceStoreRequest(testFilePath);
    resourceRequest.getRequestContext().put(AccessManager.REQUEST_REMOTE_ADDRESS, "127.0.0.1");

    AbstractStorageItem storageItem =
        localRepositoryStorageUnderTest.retrieveItem(repository, resourceRequest);

    MatcherAssert.assertThat(storageItem, Matchers.notNullValue());
    MatcherAssert.assertThat(
        storageItem.getLastRequested(), Matchers.greaterThan(originalLastAccessTime));

    Mockito.verify(attributeStorageSpy, Mockito.times(1))
        .putAttributes(Mockito.<RepositoryItemUid>any(), Mockito.<Attributes>any());
    Mockito.verify(attributeStorageSpy, Mockito.times(1))
        .getAttributes(Mockito.<RepositoryItemUid>any());
  }
Exemplo n.º 2
0
  private void mirrorRelativeItem(
      ResourceStoreRequest remoteRequest, ResourceStoreRequest localRequest, Set<String> mirrored)
      throws StorageException, IllegalOperationException, ItemNotFoundException {
    AbstractStorageItem item = (AbstractStorageItem) retrieveItem(true, remoteRequest);

    // cerating update sites may not name there jars as we expect,
    // if thats the case, download as they request, but store in local storage normalized, this
    // of course means updating the mirrored list so the file isn't deleted upon completion of
    // mirror process
    if (localRequest != null) {
      if (!mirrored.contains(localRequest.getRequestPath())) {
        mirrored.remove(remoteRequest.getRequestPath());
        mirrored.add(localRequest.getRequestPath());
      }

      // update the uid
      item.setRepositoryItemUid(createUid(localRequest.getRequestPath()));

      // update the resource store request
      item.setResourceStoreRequest(localRequest);

      // cache locally
      doCacheItem(item);
    }
  }
  @BenchmarkOptions(benchmarkRounds = 10, warmupRounds = 1)
  @Test
  public void validateRetieveItemWithOutLastAccessUpdateTimeDelay()
      throws LocalStorageException, ItemNotFoundException, IOException {
    // do the test, but make sure the _iterations_ will not get out of the "resolution" span!
    // Note: this test is just broken as is, what guarantees it will finish the cycles in given X
    // millis?
    // Meaning, the assertions + rounds is wrong.
    ((DefaultAttributesHandler) repository.getAttributesHandler())
        .setLastRequestedResolution(30000L);
    AttributeStorage attributeStorageSpy =
        Mockito.spy(repository.getAttributesHandler().getAttributeStorage());
    repository.getAttributesHandler().setAttributeStorage(attributeStorageSpy);

    ResourceStoreRequest resourceRequest = new ResourceStoreRequest(testFilePath);
    resourceRequest.getRequestContext().put(AccessManager.REQUEST_REMOTE_ADDRESS, "127.0.0.1");

    AbstractStorageItem storageItem =
        localRepositoryStorageUnderTest.retrieveItem(repository, resourceRequest);

    MatcherAssert.assertThat(storageItem, Matchers.notNullValue());
    MatcherAssert.assertThat(
        storageItem.getLastRequested(), Matchers.equalTo(originalLastAccessTime));

    Mockito.verify(attributeStorageSpy, Mockito.times(0))
        .putAttributes(Mockito.<RepositoryItemUid>any(), Mockito.<Attributes>any());
    Mockito.verify(attributeStorageSpy, Mockito.times(1))
        .getAttributes(Mockito.<RepositoryItemUid>any());
  }
  @BenchmarkOptions(benchmarkRounds = 10, warmupRounds = 1)
  @Test
  public void testRetieveItemWithoutLastAccessUpdate()
      throws LocalStorageException, ItemNotFoundException {
    ResourceStoreRequest resourceRequest = new ResourceStoreRequest(testFilePath);

    AbstractStorageItem storageItem =
        localRepositoryStorageUnderTest.retrieveItem(repository, resourceRequest);

    MatcherAssert.assertThat(storageItem, Matchers.notNullValue());
    MatcherAssert.assertThat(
        storageItem.getLastRequested(), Matchers.equalTo(originalLastAccessTime));
  }
  @BenchmarkOptions(benchmarkRounds = 10, warmupRounds = 1)
  @Test
  public void testRetieveItemWithLastAccessUpdate()
      throws LocalStorageException, ItemNotFoundException {
    ResourceStoreRequest resourceRequest = new ResourceStoreRequest(testFilePath);
    resourceRequest.getRequestContext().put(AccessManager.REQUEST_REMOTE_ADDRESS, "127.0.0.1");

    AbstractStorageItem storageItem =
        localRepositoryStorageUnderTest.retrieveItem(repository, resourceRequest);

    MatcherAssert.assertThat(storageItem, Matchers.notNullValue());
    MatcherAssert.assertThat(
        storageItem.getLastRequested(), Matchers.greaterThan(originalLastAccessTime));
  }
Exemplo n.º 6
0
  protected StorageItem mangle(
      boolean isList, ResourceStoreRequest request, RequestRoute route, StorageItem item)
      throws AccessDeniedException, ItemNotFoundException, IllegalOperationException,
          StorageException {
    if (isList) {
      ((AbstractStorageItem) item)
          .setPath(ItemPathUtils.concatPaths(route.getOriginalRequestPath(), item.getName()));
    } else {
      ((AbstractStorageItem) item).setPath(route.getOriginalRequestPath());
    }

    if (isFollowLinks() && item instanceof StorageLinkItem) {
      return dereferenceLink((StorageLinkItem) item);
    } else {
      return item;
    }
  }
  @Override
  public void storeItemWithChecksums(boolean fromTask, AbstractStorageItem item)
      throws UnsupportedStorageOperationException, IllegalOperationException, StorageException {
    if (getLogger().isDebugEnabled()) {
      getLogger().debug("storeItemWithChecksums() :: " + item.getRepositoryItemUid().toString());
    }

    getArtifactStoreHelper().storeItemWithChecksums(fromTask, item);
  }
  @BenchmarkOptions(benchmarkRounds = 10, warmupRounds = 1)
  @Test
  public void validateRetieveItemWithoutLastAccessUpdate()
      throws LocalStorageException, ItemNotFoundException, IOException {
    AttributeStorage attributeStorageSpy =
        Mockito.spy(repository.getAttributesHandler().getAttributeStorage());
    repository.getAttributesHandler().setAttributeStorage(attributeStorageSpy);

    ResourceStoreRequest resourceRequest = new ResourceStoreRequest(testFilePath);

    AbstractStorageItem storageItem =
        localRepositoryStorageUnderTest.retrieveItem(repository, resourceRequest);

    MatcherAssert.assertThat(storageItem, Matchers.notNullValue());
    MatcherAssert.assertThat(
        storageItem.getLastRequested(), Matchers.equalTo(originalLastAccessTime));

    Mockito.verify(attributeStorageSpy, Mockito.times(1))
        .getAttributes(Mockito.<RepositoryItemUid>any());
  }
Exemplo n.º 9
0
  /**
   * Mirror an absolute item (plugin or feature) will retrieve from remote request, and store in
   * local request
   *
   * @param absoluteUrl
   * @param remoteStoreRequest
   * @param basePath
   * @param localStoreRequest
   * @return
   * @throws RemoteAccessException
   * @throws StorageException
   * @throws ItemNotFoundException
   */
  private File mirrorAbsoluteItem(
      String absoluteUrl,
      ResourceStoreRequest remoteStoreRequest,
      String basePath,
      ResourceStoreRequest localStoreRequest,
      Set<String> mirrored)
      throws RemoteAccessException, StorageException, ItemNotFoundException {
    // chop off the baseDir from the request, as we only care about the file in this case
    remoteStoreRequest.pushRequestPath(
        remoteStoreRequest.getRequestPath().substring(basePath.length()));

    // we need to chop it up here to remove filename from url, as that is in request
    AbstractStorageItem item =
        getRemoteStorage().retrieveItem(this, remoteStoreRequest, absoluteUrl);

    // now put the basePath back on
    remoteStoreRequest.popRequestPath();

    if (localStoreRequest == null) {
      localStoreRequest = remoteStoreRequest;
    } else {
      // update the list of what we have mirrored, since we have changed filename
      if (!mirrored.contains(localStoreRequest.getRequestPath())) {
        mirrored.remove(remoteStoreRequest.getRequestPath());
        mirrored.add(localStoreRequest.getRequestPath());
      }

      // update the uid
      item.setRepositoryItemUid(createUid(localStoreRequest.getRequestPath()));

      // update the resource store request
      item.setResourceStoreRequest(localStoreRequest);
    }

    // cache locally
    doCacheItem(item);

    return getLocalStorage().getFileFromBase(this, localStoreRequest);
  }