Search in sources :

Example 1 with IndyContentBrowseClientModule

use of org.commonjava.indy.content.browse.client.IndyContentBrowseClientModule in project indy by Commonjava.

the class MetaListingRescheduleTimeoutTest method timeout.

// @Ignore // content listing is disabled for now, 2018/4/3
@Test
@Category(TimingDependent.class)
public void timeout() throws Exception {
    final int METADATA_TIMEOUT_SECONDS = 4;
    final int METADATA_TIMEOUT_WAITING_MILLISECONDS = 3000;
    final String repoId = "test-repo";
    String repoRootPath = "org/foo/bar/";
    final String repoRootUrl = server.formatUrl(repoId, repoRootPath);
    // now append the trailing '/' so Indy knows to try a directory listing...
    final String repoSubPath1 = "org/foo/bar/1.0/pom.xml";
    final String repoSubPath2 = "org/foo/bar/1.1/pom.xml";
    final String repoSubUrl1 = server.formatUrl(repoId, repoSubPath1);
    final String repoSubUrl2 = server.formatUrl(repoId, repoSubPath2);
    // mocking up a http server that expects access to metadata
    final String listingContent = "<html>" + "<head><title>Index of /org/foo/bar</title></head>" + "<body><h1>Index of /org/foo/bar/</h1>" + "<hr><pre>" + "<a href=\"1.0/\">1.0/</a>" + "<a href=\"1.1/\">1.1/</a>" + "</pre><hr></body></html>";
    server.expect(repoRootUrl, 200, listingContent);
    final String datetime = (new Date()).toString();
    server.expect(repoSubUrl1, 200, String.format("metadata %s", datetime));
    server.expect(repoSubUrl2, 200, String.format("metadata %s", datetime));
    // set up remote repository pointing to the test http server, and timeout little later
    final String changelog = "Timeout Testing: " + name.getMethodName();
    final RemoteRepository repository = new RemoteRepository(MavenPackageTypeDescriptor.MAVEN_PKG_KEY, repoId, server.formatUrl(repoId));
    repository.setMetadataTimeoutSeconds(METADATA_TIMEOUT_SECONDS);
    client.stores().create(repository, changelog, RemoteRepository.class);
    try (InputStream is = client.content().get(repository.getKey(), repoSubPath1)) {
    }
    try (InputStream is = client.content().get(repository.getKey(), repoSubPath2)) {
    }
    IndyContentBrowseClientModule browseClientModule = client.module(IndyContentBrowseClientModule.class);
    // first time trigger normal content storage with timeout, should be 4s
    logger.debug("Start to request listing of {}", repoRootPath);
    final ContentBrowseResult content = browseClientModule.getContentList(repository.getKey(), repoRootPath);
    assertThat("no metadata result", content, notNullValue());
    logger.debug("### will begin to get content");
    final String listingMetaPath = repoRootPath + ".listing.txt";
    KeyedLocation location = LocationUtils.toLocation(repository);
    File listingMetaFile = getPhysicalStorageFile(location, listingMetaPath);
    assertThat(".listing doesn't exist: " + listingMetaFile, listingMetaFile.exists(), equalTo(true));
    // wait for first time
    sleepAndRunFileGC(METADATA_TIMEOUT_WAITING_MILLISECONDS);
    // as the metadata content re-request, the metadata timeout interval should NOT be re-scheduled
    browseClientModule.getContentList(repository.getKey(), repoRootPath);
    // will wait second time for a longer period
    sleepAndRunFileGC(METADATA_TIMEOUT_WAITING_MILLISECONDS * getTestTimeoutMultiplier());
    // logger.info( "Checking whether metadata file {} has been deleted...", listingMetaFile );
    // as rescheduled, the artifact should not be deleted
    assertThat("artifact should be removed as the rescheduled of metadata should not succeed", listingMetaFile.exists(), equalTo(false));
}
Also used : KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) InputStream(java.io.InputStream) ContentBrowseResult(org.commonjava.indy.content.browse.model.ContentBrowseResult) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyContentBrowseClientModule(org.commonjava.indy.content.browse.client.IndyContentBrowseClientModule) File(java.io.File) Date(java.util.Date) Category(org.junit.experimental.categories.Category) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest) Test(org.junit.Test)

Aggregations

File (java.io.File)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 IndyContentBrowseClientModule (org.commonjava.indy.content.browse.client.IndyContentBrowseClientModule)1 ContentBrowseResult (org.commonjava.indy.content.browse.model.ContentBrowseResult)1 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)1 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)1 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)1 Test (org.junit.Test)1 Category (org.junit.experimental.categories.Category)1