use of org.commonjava.indy.folo.client.IndyFoloAdminClientModule 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));
}
use of org.commonjava.indy.folo.client.IndyFoloAdminClientModule in project indy by Commonjava.
the class DuplicateStoreAndVerifyTrackedRecordTest method run.
@Test
public void run() throws Exception {
final IndyFoloContentClientModule content = client.module(IndyFoloContentClientModule.class);
final IndyFoloAdminClientModule admin = client.module(IndyFoloAdminClientModule.class);
final String trackingId = newName();
final byte[] b = ("This is a test: " + System.nanoTime()).getBytes();
final InputStream stream = new ByteArrayInputStream(b);
// 30
System.out.println(">>> " + b.length);
final byte[] b2 = ("This is another test: " + System.nanoTime()).getBytes();
final InputStream stream2 = new ByteArrayInputStream(b2);
// 36
System.out.println(">>> " + b2.length);
System.out.println(">>> store stream");
content.store(trackingId, storeKey, path, stream);
System.out.println(">>> store stream 2");
PathInfo store = content.store(trackingId, storeKey, path, stream2);
System.out.println(">>> Store content length: " + store.getContentLength());
boolean b1 = admin.sealTrackingRecord(trackingId);
System.out.println(">>> seal tracking record: " + b1);
TrackedContentDTO report = admin.getTrackingReport(trackingId);
Set<TrackedContentEntryDTO> uploads = report.getUploads();
uploads.forEach(et -> {
System.out.println(">>> md5: " + et.getMd5() + ", size=" + et.getSize());
System.out.println(">>> B2: " + b2.length);
System.out.println(">>> B2 long: " + (long) b2.length);
assertThat("Mismatched size for: " + et.getPath(), et.getSize(), equalTo((long) b2.length));
});
}
use of org.commonjava.indy.folo.client.IndyFoloAdminClientModule in project indy by Commonjava.
the class RemoveFilesInTrackingReportTest 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 a = "/path/to/1/foo-1.jar";
final String b = "/path/to/2/foo-2.jar";
final String c = "/path/to/3/foo-3.jar";
for (String path : Arrays.asList(a, b)) {
client.module(IndyFoloContentClientModule.class).store(trackingId, hosted, STORE, path, stream);
}
StoreKey key = new StoreKey(PKG_TYPE_MAVEN, hosted, STORE);
client.content().store(key, c, stream);
IndyFoloAdminClientModule adminModule = client.module(IndyFoloAdminClientModule.class);
boolean success = adminModule.sealTrackingRecord(trackingId);
assertThat(success, equalTo(true));
boolean exists;
for (String path : Arrays.asList(a, b)) {
exists = client.content().exists(key, path);
assertThat("The file does not exists.", exists, equalTo(true));
}
exists = client.content().exists(key, c);
assertThat("The file does not exists.", exists, equalTo(true));
BatchDeleteRequest request = new BatchDeleteRequest();
request.setStoreKey(key);
request.setTrackingID(trackingId);
adminModule.deleteFilesFromStoreByTrackingID(request);
for (String path : Arrays.asList(a, b)) {
exists = client.content().exists(key, path);
assertThat("The file is not removed.", exists, equalTo(false));
}
exists = client.content().exists(key, c);
assertThat("The file does not exists.", exists, equalTo(true));
}
use of org.commonjava.indy.folo.client.IndyFoloAdminClientModule in project indy by Commonjava.
the class FoloBackupListenerTest 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());
// /////////////////////////////////////////////////////////////////////////////
// the above are copied from StoreFileAndVerifyInTrackingReportTest
// next, we check the backup dir contains two files, one from startup action, the other is just added
// **/
// File f1 = new File( dataDir, FOLO_DIR + "/" + BAK_DIR +"/sealed/" + trackingId );
// assertTrue( f1.exists() );
File f2 = new File(dataDir, FOLO_DIR + "/" + BAK_DIR + "/sealed");
assertDumped(f2);
}
use of org.commonjava.indy.folo.client.IndyFoloAdminClientModule in project indy by Commonjava.
the class ExportAndImportTrackingReportTest method run.
@Test
public void run() throws Exception {
String[] ret = retrieveAndSeal(repoId, path1, "This is a test.");
String trackingId_1 = ret[0];
ret = retrieveAndSeal(repoId, path2, "This is a another test.");
String trackingId_2 = ret[0];
IndyFoloAdminClientModule adminClientModule = client.module(IndyFoloAdminClientModule.class);
InputStream stream = adminClientModule.exportTrackingReportZip();
// check the folo-sealed.zip exists under data/folo/
File zipFile = new File(dataDir, FOLO_DIR + "/" + FOLO_SEALED_ZIP);
assertTrue(zipFile.exists());
// FileUtils.copyFile(zipFile, new File("/tmp/" + FOLO_SEALED_ZIP));
// to bytes
byte[] bytes;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
copy(stream, baos);
bytes = baos.toByteArray();
stream.close();
// read to a list
final List<TrackedContent> list = new ArrayList<>();
readZipInputStreamAnd(new ByteArrayInputStream(bytes), (record) -> list.add(record));
// **/ Disabled behavour because we need to keep audit logs
// check
// final List<String> trackingIds = check( list );
// assertTrue( trackingIds.contains( trackingId_1 ) );
// assertTrue( trackingIds.contains( trackingId_2 ) );
// clear all
// trackingIds.forEach( id ->
// {
// try
// {
// adminClientModule.clearTrackingRecord( id );
// }
// catch ( IndyClientException e )
// {
// e.printStackTrace();
// }
// } );
// **/ Disabled behavour because we need to keep audit logs
//
// check ids are cleaned
// TrackingIdsDTO idsDTO = adminClientModule.getTrackingIds( FOLO_TYPE_SEALED );
// assertNull( idsDTO );
// import
// adminClientModule.importTrackingReportZip( new ByteArrayInputStream( bytes ) );
// check again
// idsDTO = adminClientModule.getTrackingIds( FOLO_TYPE_SEALED );
// checkIdsDTO( idsDTO, trackingIds, adminClientModule );
// **
}
Aggregations