use of org.commonjava.indy.client.core.helper.PathInfo in project indy by Commonjava.
the class DownloadWhileProxyingInProgressTest method downloadWhileSlowProxyCompletes.
@Test
public void downloadWhileSlowProxyCompletes() 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(2);
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, 5000, latch);
newThread("download", download).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 Download started: {}\n Download ended: {}", input.getStartTime(), input.getEndTime(), download.getStartTime(), download.getEndTime());
assertThat(download.getContent().toByteArray(), equalTo(data));
assertThat(input.getEndTime() > download.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 AbstractMetadataTimeoutWorkingTest method setupRepo.
@Before
public void setupRepo() throws Exception {
final String pomUrl = server.formatUrl(repoId, pomPath);
final String metadataUrl = server.formatUrl(repoId, metadataPath);
final String archetypeUrl = server.formatUrl(repoId, archetypePath);
// 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));
server.expect(archetypeUrl, 200, String.format("archetype %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 = createRemoteRepository();
client.stores().create(repository, changelog, RemoteRepository.class);
// ensure the pom exist before the timeout checking
final 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));
pomFile = Paths.get(fixture.getBootOptions().getIndyHome(), "var/lib/indy/storage", MAVEN_PKG_KEY, remote.singularEndpointName() + "-" + repoId, pomPath).toFile();
assertThat("pom doesn't exist: " + pomFile, pomFile.exists(), equalTo(true));
// ensure the metadata exist before the timeout checking
final 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));
metadataFile = Paths.get(fixture.getBootOptions().getIndyHome(), "var/lib/indy/storage", MAVEN_PKG_KEY, remote.singularEndpointName() + "-" + repoId, metadataPath).toFile();
assertThat("metadata doesn't exist", metadataFile.exists(), equalTo(true));
// ensure the archetype exist before the timeout checking
final PathInfo archetypeResult = client.content().getInfo(remote, repoId, archetypePath);
// force storage
client.content().get(remote, repoId, archetypePath).close();
assertThat("no archetype result", archetypeResult, notNullValue());
assertThat("archetype doesn't exist", archetypeResult.exists(), equalTo(true));
archetypeFile = Paths.get(fixture.getBootOptions().getIndyHome(), "var/lib/indy/storage", MAVEN_PKG_KEY, remote.singularEndpointName() + "-" + repoId, archetypePath).toFile();
assertThat("archetype doesn't exist: " + archetypeFile, archetypeFile.exists(), equalTo(true));
}
use of org.commonjava.indy.client.core.helper.PathInfo in project indy by Commonjava.
the class DownloadContentHasLengthHeaderTest method proxyRemoteArtifact.
@Test
public void proxyRemoteArtifact() throws Exception {
byte[] data = ("This is a test: " + System.nanoTime()).getBytes();
final InputStream stream = new ByteArrayInputStream(data);
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);
try (HttpResources httpResources = client.module(IndyRawHttpModule.class).getHttp().getRaw(client.content().contentPath(remote, STORE, path))) {
HttpResponse response = httpResources.getResponse();
String contentLength = response.getFirstHeader("Content-Length").getValue();
assertThat("Wrong content-length for download: " + contentLength + " (should have been: " + data.length + ")", contentLength, equalTo(Integer.toString(data.length)));
}
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 IndyFoloContentClientModuleTest method deprecatedContentStore.
@Test
public void deprecatedContentStore() throws Exception {
String tid = "foo";
String repo = "central";
String path = "org/foo/bar/1/bar-1.pom";
String fullPath = String.format("/api/folo/track/%s/maven/remote/%s/%s", tid, repo, path);
server.expect("PUT", server.formatUrl(fullPath), 201, "");
String value = "<project><modelVersion>4.0.0</modelVersion><groupId>org.foo</groupId><artifactId>bar</artifactId>" + "<version>1</version><packaging>pom</packaging></project>";
PathInfo info = module.store(tid, remote, "central", path, new ByteArrayInputStream(value.getBytes()));
}
use of org.commonjava.indy.client.core.helper.PathInfo in project indy by Commonjava.
the class StoreAndVerifyReturnedPathInfoForTrackedHostedRepoTest method storeFileAndVerifyReturnedInfo.
@Test
public void storeFileAndVerifyReturnedInfo() throws Exception {
final String trackingId = newName();
final InputStream stream = new ByteArrayInputStream(("This is a test: " + System.nanoTime()).getBytes());
final String path = "/path/to/foo.class";
final PathInfo result = client.module(IndyFoloContentClientModule.class).store(trackingId, hosted, STORE, path, stream);
System.out.println(result);
assertThat(result, notNullValue());
assertThat(result.exists(), equalTo(true));
}
Aggregations