Search in sources :

Example 1 with ChecksumBlobStoreFormat

use of org.opensearch.repositories.blobstore.ChecksumBlobStoreFormat in project OpenSearch by opensearch-project.

the class BlobStoreFormatTests method testBlobStoreOperations.

public void testBlobStoreOperations() throws IOException {
    BlobStore blobStore = createTestBlobStore();
    BlobContainer blobContainer = blobStore.blobContainer(BlobPath.cleanPath());
    ChecksumBlobStoreFormat<BlobObj> checksumSMILE = new ChecksumBlobStoreFormat<>(BLOB_CODEC, "%s", BlobObj::fromXContent);
    // Write blobs in different formats
    checksumSMILE.write(new BlobObj("checksum smile"), blobContainer, "check-smile", false);
    checksumSMILE.write(new BlobObj("checksum smile compressed"), blobContainer, "check-smile-comp", true);
    // Assert that all checksum blobs can be read
    assertEquals(checksumSMILE.read(blobContainer, "check-smile", xContentRegistry()).getText(), "checksum smile");
    assertEquals(checksumSMILE.read(blobContainer, "check-smile-comp", xContentRegistry()).getText(), "checksum smile compressed");
}
Also used : ChecksumBlobStoreFormat(org.opensearch.repositories.blobstore.ChecksumBlobStoreFormat) BlobContainer(org.opensearch.common.blobstore.BlobContainer) FsBlobStore(org.opensearch.common.blobstore.fs.FsBlobStore) BlobStore(org.opensearch.common.blobstore.BlobStore)

Example 2 with ChecksumBlobStoreFormat

use of org.opensearch.repositories.blobstore.ChecksumBlobStoreFormat in project OpenSearch by opensearch-project.

the class BlobStoreFormatTests method testBlobCorruption.

public void testBlobCorruption() throws IOException {
    BlobStore blobStore = createTestBlobStore();
    BlobContainer blobContainer = blobStore.blobContainer(BlobPath.cleanPath());
    String testString = randomAlphaOfLength(randomInt(10000));
    BlobObj blobObj = new BlobObj(testString);
    ChecksumBlobStoreFormat<BlobObj> checksumFormat = new ChecksumBlobStoreFormat<>(BLOB_CODEC, "%s", BlobObj::fromXContent);
    checksumFormat.write(blobObj, blobContainer, "test-path", randomBoolean());
    assertEquals(checksumFormat.read(blobContainer, "test-path", xContentRegistry()).getText(), testString);
    randomCorruption(blobContainer, "test-path");
    try {
        checksumFormat.read(blobContainer, "test-path", xContentRegistry());
        fail("Should have failed due to corruption");
    } catch (OpenSearchCorruptionException ex) {
        assertThat(ex.getMessage(), containsString("test-path"));
    } catch (EOFException ex) {
    // This can happen if corrupt the byte length
    }
}
Also used : ChecksumBlobStoreFormat(org.opensearch.repositories.blobstore.ChecksumBlobStoreFormat) OpenSearchCorruptionException(org.opensearch.OpenSearchCorruptionException) BlobContainer(org.opensearch.common.blobstore.BlobContainer) EOFException(java.io.EOFException) Matchers.containsString(org.hamcrest.Matchers.containsString) FsBlobStore(org.opensearch.common.blobstore.fs.FsBlobStore) BlobStore(org.opensearch.common.blobstore.BlobStore)

Example 3 with ChecksumBlobStoreFormat

use of org.opensearch.repositories.blobstore.ChecksumBlobStoreFormat in project OpenSearch by opensearch-project.

the class BlobStoreFormatTests method testCompressionIsApplied.

public void testCompressionIsApplied() throws IOException {
    BlobStore blobStore = createTestBlobStore();
    BlobContainer blobContainer = blobStore.blobContainer(BlobPath.cleanPath());
    StringBuilder veryRedundantText = new StringBuilder();
    for (int i = 0; i < randomIntBetween(100, 300); i++) {
        veryRedundantText.append("Blah ");
    }
    ChecksumBlobStoreFormat<BlobObj> checksumFormat = new ChecksumBlobStoreFormat<>(BLOB_CODEC, "%s", BlobObj::fromXContent);
    BlobObj blobObj = new BlobObj(veryRedundantText.toString());
    checksumFormat.write(blobObj, blobContainer, "blob-comp", true);
    checksumFormat.write(blobObj, blobContainer, "blob-not-comp", false);
    Map<String, BlobMetadata> blobs = blobContainer.listBlobsByPrefix("blob-");
    assertEquals(blobs.size(), 2);
    assertThat(blobs.get("blob-not-comp").length(), greaterThan(blobs.get("blob-comp").length()));
}
Also used : ChecksumBlobStoreFormat(org.opensearch.repositories.blobstore.ChecksumBlobStoreFormat) BlobMetadata(org.opensearch.common.blobstore.BlobMetadata) BlobContainer(org.opensearch.common.blobstore.BlobContainer) Matchers.containsString(org.hamcrest.Matchers.containsString) FsBlobStore(org.opensearch.common.blobstore.fs.FsBlobStore) BlobStore(org.opensearch.common.blobstore.BlobStore)

Aggregations

BlobContainer (org.opensearch.common.blobstore.BlobContainer)3 BlobStore (org.opensearch.common.blobstore.BlobStore)3 FsBlobStore (org.opensearch.common.blobstore.fs.FsBlobStore)3 ChecksumBlobStoreFormat (org.opensearch.repositories.blobstore.ChecksumBlobStoreFormat)3 Matchers.containsString (org.hamcrest.Matchers.containsString)2 EOFException (java.io.EOFException)1 OpenSearchCorruptionException (org.opensearch.OpenSearchCorruptionException)1 BlobMetadata (org.opensearch.common.blobstore.BlobMetadata)1