Search in sources :

Example 16 with TrackedContentDTO

use of org.commonjava.indy.folo.dto.TrackedContentDTO in project indy by Commonjava.

the class RecalculateMissingChecksumForTrackingRecordTest method run.

@BMRules(rules = { @BMRule(name = "setup_metadata_retrieval_countdown", targetClass = "^org.commonjava.indy.content.ContentDigester", isInterface = true, targetMethod = "<init>", targetLocation = "ENTRY", action = "System.out.println(\"SETUP COUNTDOWN\"); createCountDown(\"COUNTDOWN\", 1);"), @BMRule(name = "prevent_first_metadata_retrieval", targetClass = "^org.commonjava.indy.content.ContentDigester", isInterface = true, targetMethod = "getContentMetadata", targetLocation = "ENTRY", binding = "path:String = $1.getPath();", condition = "path.endsWith(\"path/to/foo.class\") && !countDown(\"COUNTDOWN\")", action = "System.out.println(\"RETURN NULL\"); return null;") })
@Test
public void run() throws Exception {
    final String trackingId = newName();
    final String repoId = "repo";
    final String path = "/path/to/foo.class";
    final InputStream stream = new ByteArrayInputStream("This is a test with the same content each time.".getBytes());
    server.expect(server.formatUrl(repoId, path), 200, stream);
    RemoteRepository rr = new RemoteRepository(repoId, server.formatUrl(repoId));
    rr = client.stores().create(rr, "adding test remote", RemoteRepository.class);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final InputStream in = client.module(IndyFoloContentClientModule.class).get(trackingId, remote, repoId, path);
    IOUtils.copy(in, baos);
    in.close();
    final byte[] bytes = baos.toByteArray();
    final String md5 = md5Hex(bytes);
    final String sha256 = sha256Hex(bytes);
    assertThat(md5, equalTo(DigestUtils.md5Hex(bytes)));
    assertThat(sha256, equalTo(DigestUtils.sha256Hex(bytes)));
    waitForEventPropagation();
    assertThat(client.module(IndyFoloAdminClientModule.class).sealTrackingRecord(trackingId), equalTo(true));
    final TrackedContentDTO report = client.module(IndyFoloAdminClientModule.class).getTrackingReport(trackingId);
    assertThat(report, notNullValue());
    final Set<TrackedContentEntryDTO> downloads = report.getDownloads();
    assertThat(downloads, notNullValue());
    assertThat(downloads.size(), equalTo(1));
    final TrackedContentEntryDTO entry = downloads.iterator().next();
    System.out.println(entry);
    assertThat(entry, notNullValue());
    assertThat(entry.getStoreKey(), equalTo(new StoreKey(remote, repoId)));
    assertThat(entry.getPath(), equalTo(path));
    assertThat(entry.getLocalUrl(), equalTo(client.content().contentUrl(remote, repoId, path)));
    assertThat(entry.getOriginUrl(), equalTo(server.formatUrl(repoId, path)));
    assertThat(entry.getMd5(), equalTo(md5));
    assertThat(entry.getSha256(), equalTo(sha256));
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StoreKey(org.commonjava.indy.model.core.StoreKey) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) BytemanTest(org.commonjava.indy.ftest.core.category.BytemanTest) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 17 with TrackedContentDTO

use of org.commonjava.indy.folo.dto.TrackedContentDTO in project indy by Commonjava.

the class RetrieveTrackingReportAfterCacheExpirationTest method run.

@Test
public void run() throws Exception {
    final String trackingId = newName();
    final String repoId = "repo";
    final String path = "/path/to/foo.class";
    final InputStream stream = new ByteArrayInputStream(("This is a test: " + System.nanoTime()).getBytes());
    server.expect(server.formatUrl(repoId, path), 200, stream);
    RemoteRepository rr = new RemoteRepository(repoId, server.formatUrl(repoId));
    rr = client.stores().create(rr, "adding test remote", RemoteRepository.class);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final InputStream in = client.module(IndyFoloContentClientModule.class).get(trackingId, remote, repoId, path);
    IOUtils.copy(in, baos);
    in.close();
    final byte[] bytes = baos.toByteArray();
    final String md5 = md5Hex(bytes);
    final String sha256 = sha256Hex(bytes);
    assertThat(md5, equalTo(DigestUtils.md5Hex(bytes)));
    assertThat(sha256, equalTo(DigestUtils.sha256Hex(bytes)));
    // sleep so the cache evicts the record
    Thread.sleep(2000);
    assertThat(client.module(IndyFoloAdminClientModule.class).sealTrackingRecord(trackingId), equalTo(true));
    final TrackedContentDTO report = client.module(IndyFoloAdminClientModule.class).getTrackingReport(trackingId);
    assertThat(report, notNullValue());
    final Set<TrackedContentEntryDTO> downloads = report.getDownloads();
    assertThat(downloads, notNullValue());
    assertThat(downloads.size(), equalTo(1));
    final TrackedContentEntryDTO entry = downloads.iterator().next();
    System.out.println(entry);
    assertThat(entry, notNullValue());
    assertThat(entry.getStoreKey(), equalTo(new StoreKey(remote, repoId)));
    assertThat(entry.getPath(), equalTo(path));
    assertThat(entry.getLocalUrl(), equalTo(client.content().contentUrl(remote, repoId, path)));
    assertThat(entry.getOriginUrl(), equalTo(server.formatUrl(repoId, path)));
    assertThat(entry.getMd5(), equalTo(md5));
    assertThat(entry.getSha256(), equalTo(sha256));
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StoreKey(org.commonjava.indy.model.core.StoreKey) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Test(org.junit.Test)

Example 18 with TrackedContentDTO

use of org.commonjava.indy.folo.dto.TrackedContentDTO in project indy by Commonjava.

the class StoreFileAndRecalculateTrackingEntryTest method run.

@Test
public void run() throws Exception {
    final String trackingId = newName();
    byte[] oldData = ("This is a test: " + System.nanoTime()).getBytes();
    InputStream stream = new ByteArrayInputStream(oldData);
    final String path = "/path/to/foo.class";
    client.module(IndyFoloContentClientModule.class).store(trackingId, hosted, STORE, path, stream);
    IndyFoloAdminClientModule adminModule = client.module(IndyFoloAdminClientModule.class);
    boolean success = adminModule.sealTrackingRecord(trackingId);
    assertThat(success, equalTo(true));
    TrackedContentDTO report = adminModule.getTrackingReport(trackingId);
    assertThat(report, notNullValue());
    Set<TrackedContentEntryDTO> uploads = report.getUploads();
    assertThat(uploads, notNullValue());
    assertThat(uploads.size(), equalTo(1));
    TrackedContentEntryDTO entry = uploads.iterator().next();
    System.out.println(entry);
    assertThat(entry, notNullValue());
    assertThat(entry.getStoreKey(), equalTo(new StoreKey(hosted, STORE)));
    assertThat(entry.getPath(), equalTo(path));
    assertThat(entry.getLocalUrl(), equalTo(client.content().contentUrl(hosted, STORE, path)));
    assertThat(entry.getMd5(), equalTo(md5Hex(oldData)));
    assertThat(entry.getOriginUrl(), nullValue());
    byte[] newData = ("This is a REPLACED test: " + System.nanoTime()).getBytes();
    stream = new ByteArrayInputStream(newData);
    client.content().store(hosted, STORE, path, stream);
    report = adminModule.recalculateTrackingRecord(trackingId);
    assertThat(report, notNullValue());
    uploads = report.getUploads();
    assertThat(uploads, notNullValue());
    assertThat(uploads.size(), equalTo(1));
    entry = uploads.iterator().next();
    System.out.println(entry);
    assertThat(entry, notNullValue());
    assertThat(entry.getStoreKey(), equalTo(new StoreKey(hosted, STORE)));
    assertThat(entry.getPath(), equalTo(path));
    assertThat(entry.getLocalUrl(), equalTo(client.content().contentUrl(hosted, STORE, path)));
    assertThat(entry.getMd5(), equalTo(md5Hex(newData)));
    assertThat(entry.getOriginUrl(), nullValue());
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) StoreKey(org.commonjava.indy.model.core.StoreKey) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Test(org.junit.Test)

Example 19 with TrackedContentDTO

use of org.commonjava.indy.folo.dto.TrackedContentDTO in project indy by Commonjava.

the class StoreFileAndVerifyInTrackingReportTest method run.

@Test
public void run() 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";
    client.module(IndyFoloContentClientModule.class).store(trackingId, hosted, STORE, path, stream);
    IndyFoloAdminClientModule adminModule = client.module(IndyFoloAdminClientModule.class);
    boolean success = adminModule.sealTrackingRecord(trackingId);
    assertThat(success, equalTo(true));
    final TrackedContentDTO report = adminModule.getTrackingReport(trackingId);
    assertThat(report, notNullValue());
    final Set<TrackedContentEntryDTO> uploads = report.getUploads();
    assertThat(uploads, notNullValue());
    assertThat(uploads.size(), equalTo(1));
    final TrackedContentEntryDTO entry = uploads.iterator().next();
    System.out.println(entry);
    assertThat(entry, notNullValue());
    assertThat(entry.getStoreKey(), equalTo(new StoreKey(hosted, STORE)));
    assertThat(entry.getPath(), equalTo(path));
    assertThat(entry.getLocalUrl(), equalTo(client.content().contentUrl(hosted, STORE, path)));
    assertThat(entry.getOriginUrl(), nullValue());
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) StoreKey(org.commonjava.indy.model.core.StoreKey) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Test(org.junit.Test)

Example 20 with TrackedContentDTO

use of org.commonjava.indy.folo.dto.TrackedContentDTO in project indy by Commonjava.

the class StoreFileThenDownloadThenUploadAndVerifyInTrackingReportTest method sealAndCheck.

void sealAndCheck(String trackingId) throws IndyClientException {
    // seal
    IndyFoloAdminClientModule adminModule = client.module(IndyFoloAdminClientModule.class);
    boolean success = adminModule.sealTrackingRecord(trackingId);
    assertThat(success, equalTo(true));
    // check report
    final TrackedContentDTO report = adminModule.getTrackingReport(trackingId);
    assertThat(report, notNullValue());
    final Set<TrackedContentEntryDTO> downloads = report.getDownloads();
    assertThat(downloads, notNullValue());
    assertThat(downloads.size(), equalTo(1));
    final Set<TrackedContentEntryDTO> uploads = report.getUploads();
    assertThat(uploads, notNullValue());
    assertThat(uploads.size(), equalTo(1));
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO)

Aggregations

TrackedContentDTO (org.commonjava.indy.folo.dto.TrackedContentDTO)24 TrackedContentEntryDTO (org.commonjava.indy.folo.dto.TrackedContentEntryDTO)18 IndyFoloAdminClientModule (org.commonjava.indy.folo.client.IndyFoloAdminClientModule)17 Test (org.junit.Test)15 InputStream (java.io.InputStream)13 IndyFoloContentClientModule (org.commonjava.indy.folo.client.IndyFoloContentClientModule)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 StoreKey (org.commonjava.indy.model.core.StoreKey)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)6 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 Path (javax.ws.rs.Path)4 ApiResponse (io.swagger.annotations.ApiResponse)3 GET (javax.ws.rs.GET)3 Response (javax.ws.rs.core.Response)3 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)3 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)3 BytemanTest (org.commonjava.indy.ftest.core.category.BytemanTest)3 BMRules (org.jboss.byteman.contrib.bmunit.BMRules)3