Search in sources :

Example 1 with ElasticsearchCorruptionException

use of org.elasticsearch.ElasticsearchCorruptionException in project elasticsearch by elastic.

the class BlobStoreFormatIT method testBlobCorruption.

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

Aggregations

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