use of org.commonjava.indy.client.core.helper.PathInfo in project indy by Commonjava.
the class ContentRescheduleTimeoutTest method timeout.
@Test
@Category(TimingDependent.class)
public void timeout() throws Exception {
final String repoId = "test-repo";
final String pomPath = "org/foo/bar/1.0/bar-1.0.pom";
final String pomUrl = server.formatUrl(repoId, pomPath);
final int CACHE_TIMEOUT_SECONDS = 6;
final int CACHE_TIMEOUT_WAITING_MILLISECONDS = 3000;
// mocking up a http server that expects access to a .pom
final String datetime = (new Date()).toString();
server.expect(pomUrl, 200, String.format("pom %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(repoId, server.formatUrl(repoId));
repository.setCacheTimeoutSeconds(CACHE_TIMEOUT_SECONDS);
client.stores().create(repository, changelog, RemoteRepository.class);
// first time trigger normal content storage with timeout, should be 6s
PathInfo pomResult = client.content().getInfo(remote, repoId, pomPath);
// force storage
client.content().get(remote, repoId, pomPath).close();
assertThat("no pom result", pomResult, notNullValue());
assertThat("pom doesn't exist", pomResult.exists(), equalTo(true));
File pomFile = Paths.get(fixture.getBootOptions().getIndyHome(), "var/lib/indy/storage", MAVEN_PKG_KEY, remote.singularEndpointName() + "-" + repoId, pomPath).toFile();
assertThat("pom doesn't exist", pomFile.exists(), equalTo(true));
// wait for first 3s
Thread.sleep(CACHE_TIMEOUT_WAITING_MILLISECONDS);
// as the normal content re-request, the timeout interval should be re-scheduled
client.content().get(remote, repoId, pomPath);
// will wait another 3.5s
Thread.sleep(CACHE_TIMEOUT_WAITING_MILLISECONDS + 500);
// as rescheduled in 3s, the new timeout should be 3+6=9s, so the artifact should not be deleted
assertThat("artifact should not be removed as it is rescheduled with new request", pomFile.exists(), equalTo(true));
// another round wait for 4.5s
Thread.sleep(CACHE_TIMEOUT_WAITING_MILLISECONDS + 4500);
assertThat("artifact should be removed when new scheduled cache timeout", pomFile.exists(), equalTo(false));
}
use of org.commonjava.indy.client.core.helper.PathInfo in project indy by Commonjava.
the class DownloadContentHasLengthHeaderHostedTest method run.
@Test
public void run() throws Exception {
byte[] data = ("This is a test: " + System.nanoTime()).getBytes();
String path = "org/foo/foo-project/1/foo-1.txt";
InputStream stream = new ByteArrayInputStream(data);
client.content().store(hosted, STORE, path, stream);
String p = client.content().contentPath(hosted, STORE, path);
Map<String, String> headers = client.module(IndyRawHttpModule.class).getHttp().head(p);
logger.debug("Get headers: " + headers);
PathInfo result = client.content().getInfo(hosted, STORE, path);
assertThat("no result", result, notNullValue());
assertThat("doesn't exist", result.exists(), equalTo(true));
assertThat("content length wrong", new Long(result.getContentLength()).intValue(), equalTo(data.length));
}
use of org.commonjava.indy.client.core.helper.PathInfo in project indy by Commonjava.
the class LateJoinDownloadWhileProxyingInProgressTest method downloadTwiceWhileSlowProxyCompletes.
@Test
@Category(TimingDependent.class)
public void downloadTwiceWhileSlowProxyCompletes() throws Exception {
RemoteRepository rmt = new RemoteRepository(STORE, server.formatUrl(STORE));
rmt.setTimeoutSeconds(30);
client.stores().create(rmt, "adding test proxy", RemoteRepository.class);
final String path = "org/foo/foo-project/1/foo-1.txt";
final byte[] data = ("This is a test: " + System.nanoTime()).getBytes();
final CountDownLatch latch = new CountDownLatch(3);
final ReluctantInputStream stream = new ReluctantInputStream(data);
server.expect(server.formatUrl(STORE, path), 200, stream);
final InputTimer input = new InputTimer(stream, 10000 / data.length, latch);
newThread("input", input).start();
final DelayedDownload download = new DelayedDownload(client, new StoreKey(remote, STORE), path, 5, latch);
newThread("download", download).start();
final DelayedDownload download2 = new DelayedDownload(client, new StoreKey(remote, STORE), path, 5000, latch);
newThread("download2", download2).start();
System.out.println("Waiting for content transfers to complete.");
latch.await();
// waitForEventPropagation();
System.out.printf("Timing results:\n Input started: {}\n Input ended: {}\n Download1 started: {}\n Download1 ended: {}\\n Download2 started: {}\\n Download2 ended: {}", input.getStartTime(), input.getEndTime(), download.getStartTime(), download.getEndTime(), download2.getStartTime(), download2.getEndTime());
assertThat("First download retrieved wrong content", Arrays.equals(download.getContent().toByteArray(), data), equalTo(true));
assertThat("Second download retrieved wrong content", Arrays.equals(download2.getContent().toByteArray(), data), equalTo(true));
assertThat("First download started after input ended.", input.getEndTime() > download.getStartTime(), equalTo(true));
assertThat("Second download started after input ended.", input.getEndTime() > download2.getStartTime(), equalTo(true));
final PathInfo result = client.content().getInfo(remote, STORE, path);
assertThat("no result", result, notNullValue());
assertThat("doesn't exist", result.exists(), equalTo(true));
}
use of org.commonjava.indy.client.core.helper.PathInfo in project indy by Commonjava.
the class MixContentRescheduleTimeoutTest method timeout.
@Test
@Category(TimingDependent.class)
public void timeout() throws Exception {
final String repoId = "test-repo";
final String pomPath = "org/foo/bar/1.0/bar-1.0.pom";
final String metadataPath = "org/foo/bar/maven-metadata.xml";
final String pomUrl = server.formatUrl(repoId, pomPath);
final String metadataUrl = server.formatUrl(repoId, metadataPath);
final int CACHE_TIMEOUT_SECONDS = 8;
final int CACHE_TIMEOUT_WAITING_MILLISECONDS = 4000;
final int METADATA_TIMEOUT_SECONDS = 4;
// mocking up a http server that expects access to a .pom
final String datetime = (new Date()).toString();
server.expect(pomUrl, 200, String.format("pom %s", datetime));
server.expect(metadataUrl, 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(repoId, server.formatUrl(repoId));
repository.setCacheTimeoutSeconds(CACHE_TIMEOUT_SECONDS);
repository.setMetadataTimeoutSeconds(METADATA_TIMEOUT_SECONDS);
client.stores().create(repository, changelog, RemoteRepository.class);
// first time trigger normal content storage with timeout, should be 8s
PathInfo pomResult = client.content().getInfo(remote, repoId, pomPath);
// force storage
client.content().get(remote, repoId, pomPath).close();
assertThat("no pom result", pomResult, notNullValue());
assertThat("pom doesn't exist", pomResult.exists(), equalTo(true));
File pomFile = Paths.get(fixture.getBootOptions().getIndyHome(), "var/lib/indy/storage", MAVEN_PKG_KEY, remote.singularEndpointName() + "-" + repoId, pomPath).toFile();
assertThat("pom doesn't exist", pomFile.exists(), equalTo(true));
// first time trigger metadata storage with timeout, should be 4s
PathInfo metadataResult = client.content().getInfo(remote, repoId, metadataPath);
// force storage
client.content().get(remote, repoId, metadataPath).close();
assertThat("no metadata result", metadataResult, notNullValue());
assertThat("metadata doesn't exist", metadataResult.exists(), equalTo(true));
File metadataFile = Paths.get(fixture.getBootOptions().getIndyHome(), "var/lib/indy/storage", MAVEN_PKG_KEY, remote.singularEndpointName() + "-" + repoId, metadataPath).toFile();
assertThat("metadata doesn't exist: " + metadataFile, metadataFile.exists(), equalTo(true));
// wait for first 4s
Thread.sleep(CACHE_TIMEOUT_WAITING_MILLISECONDS);
// as the metadata re-request, the timeout interval should NOT be re-scheduled
try (InputStream is = client.content().get(remote, repoId, metadataPath)) {
}
// will wait another 4.5s
Thread.sleep(CACHE_TIMEOUT_WAITING_MILLISECONDS + 500);
// even meta file re-request @ 4s, normal content timeout should not be rescheduled, so the artifact should be deleted
assertThat("artifact should be removed even metadata rescheduled with new request", pomFile.exists(), equalTo(false));
}
use of org.commonjava.indy.client.core.helper.PathInfo in project indy by Commonjava.
the class ProxyRemoteContentTest method proxyRemoteArtifact.
@Test
public void proxyRemoteArtifact() throws Exception {
final InputStream stream = new ByteArrayInputStream(("This is a test: " + System.nanoTime()).getBytes());
final String path = "org/foo/foo-project/1/foo-1.txt";
server.expect(server.formatUrl(STORE, path), 200, stream);
client.stores().create(new RemoteRepository(STORE, server.formatUrl(STORE)), "adding test proxy", RemoteRepository.class);
final PathInfo result = client.content().getInfo(remote, STORE, path);
assertThat("no result", result, notNullValue());
assertThat("doesn't exist", result.exists(), equalTo(true));
}
Aggregations