Search in sources :

Example 1 with OpenSearchCorruptionException

use of org.opensearch.OpenSearchCorruptionException 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)

Aggregations

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