示例#1
0
  /**
   * See NXCM-4516. We are invoking "walker" using a path that points to a non-collection item (a
   * file).
   */
  @Test
  public void testWalkerRunningAgainstFileItem() throws Exception {
    // fetch some content to have on walk on something
    getRootRouter()
        .retrieveItem(
            new ResourceStoreRequest(
                "/groups/test/activemq/activemq-core/1.2/activemq-core-1.2.jar", false));
    TestWalkerProcessor wp = null;
    WalkerContext wc = null;
    wp = new TestWalkerProcessor();
    // this is a group
    wc =
        new DefaultWalkerContext(
            getRepositoryRegistry().getRepository("test"),
            new ResourceStoreRequest("/activemq/activemq-core/1.2/activemq-core-1.2.jar", true));
    wc.getProcessors().add(wp);
    walker.walk(wc);
    assertThat("Should not be stopped!", wc.isStopped(), is(false));
    if (wc.getStopCause() != null) {
      wc.getStopCause().printStackTrace();
      fail("Should be no exception!");
    }

    Assert.assertEquals(0, wp.collEnters);
    Assert.assertEquals(0, wp.collExits);
    Assert.assertEquals(0, wp.colls);
    Assert.assertEquals(1, wp.files);
    Assert.assertEquals(0, wp.links);
  }
示例#2
0
  /**
   * Tests walking an out of service repo. The walker should NOT not fail, but also NOT find any
   * items.</BR> Verifies fix for: NEXUS-4554 (which is more general then just fixing the Trash
   * task)
   */
  @Test
  public void testWalkOutOfServiceRepo() throws Exception {
    // put repo2 out of service
    String repoId = "repo2";
    M2Repository repo = (M2Repository) repositoryRegistry.getRepository(repoId);
    repo.setLocalStatus(LocalStatus.OUT_OF_SERVICE);
    repo.commitChanges();

    TestWalkerProcessor wp = null;
    WalkerContext wc = null;

    wp = new TestWalkerProcessor();

    // this is a group
    wc =
        new DefaultWalkerContext(
            getRepositoryRegistry().getRepository(repoId),
            new ResourceStoreRequest(RepositoryItemUid.PATH_ROOT, true));

    wc.getProcessors().add(wp);

    walker.walk(wc);

    Assert.assertEquals(0, wp.collEnters);
    Assert.assertEquals(0, wp.collExits);
    Assert.assertEquals(0, wp.colls);
    Assert.assertEquals(0, wp.files);
    Assert.assertEquals(0, wp.links);
  }
示例#3
0
  /**
   * NEXUS-5766: Verify that walker will continue walking if collection/item is removed while
   * walking
   */
  @Test
  public void walkWhileItemsAreRemoved() throws Exception {

    // fetch some content to have on walk on something
    getRootRouter()
        .retrieveItem(
            new ResourceStoreRequest(
                "/repositories/repo1/activemq/activemq-core/1.2/activemq-core-1.2.jar", false));
    getRootRouter()
        .retrieveItem(
            new ResourceStoreRequest(
                "/repositories/repo1/org/slf4j/slf4j-api/1.4.3/slf4j-api-1.4.3.pom", false));
    getRootRouter()
        .retrieveItem(
            new ResourceStoreRequest("/repositories/repo1/rome/rome/0.9/rome-0.9.pom", false));

    final WalkerContext wc =
        new DefaultWalkerContext(
            getRepositoryRegistry().getRepository("repo1"),
            new ResourceStoreRequest(RepositoryItemUid.PATH_ROOT, true));

    final TestWalkerProcessor wp = new TestWalkerProcessor();

    wc.getProcessors().add(wp);
    wc.getProcessors()
        .add(
            new AbstractWalkerProcessor() {
              @Override
              public void processItem(final WalkerContext context, final StorageItem item)
                  throws Exception {
                // do nothing
              }

              @Override
              public void onCollectionEnter(
                  final WalkerContext context, final StorageCollectionItem coll) throws Exception {
                if (coll.getPath().startsWith("/activemq/activemq-core")) {
                  getRootRouter()
                      .deleteItem(
                          new ResourceStoreRequest(
                              "/repositories/repo1/activemq/activemq-core", true));
                } else if (coll.getPath().startsWith("/rome/rome/0.9")) {
                  getRootRouter()
                      .deleteItem(
                          new ResourceStoreRequest(
                              "/repositories/repo1/rome/rome/0.9/rome-0.9.pom", true));
                }
              }
            });

    walker.walk(wc);

    assertThat("Should not be stopped!", wc.isStopped(), is(false));

    if (wc.getStopCause() != null) {
      wc.getStopCause().printStackTrace();
      assertThat("Should be no exception!", false);
    }

    assertThat(wp.collEnters, is(10));
    assertThat(wp.collExits, is(10));
    assertThat(wp.colls, is(0));
    assertThat(wp.files, is(2));
    assertThat(wp.links, is(0));
  }
示例#4
0
  public WalkerException(WalkerContext walkerContext, String message) {
    super(message, walkerContext.getStopCause());

    this.walkerContext = walkerContext;
  }