Search in sources :

Example 6 with BlobStoreRepository

use of org.elasticsearch.repositories.blobstore.BlobStoreRepository in project crate by crate.

the class MockEventuallyConsistentRepositoryTests method testReadAfterWriteConsistently.

public void testReadAfterWriteConsistently() throws IOException {
    MockEventuallyConsistentRepository.Context blobStoreContext = new MockEventuallyConsistentRepository.Context();
    try (BlobStoreRepository repository = new MockEventuallyConsistentRepository(new RepositoryMetadata("testRepo", "mockEventuallyConsistent", Settings.EMPTY), xContentRegistry(), BlobStoreTestUtil.mockClusterService(), blobStoreContext, random())) {
        repository.start();
        final BlobContainer blobContainer = repository.blobStore().blobContainer(repository.basePath());
        final String blobName = randomAlphaOfLength(10);
        final int lengthWritten = randomIntBetween(1, 100);
        final byte[] blobData = randomByteArrayOfLength(lengthWritten);
        blobContainer.writeBlob(blobName, new ByteArrayInputStream(blobData), lengthWritten, true);
        try (InputStream in = blobContainer.readBlob(blobName)) {
            final byte[] readBytes = new byte[lengthWritten + 1];
            final int lengthSeen = in.read(readBytes);
            assertThat(lengthSeen, equalTo(lengthWritten));
            assertArrayEquals(blobData, Arrays.copyOf(readBytes, lengthWritten));
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BlobStoreRepository(org.elasticsearch.repositories.blobstore.BlobStoreRepository) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BlobContainer(org.elasticsearch.common.blobstore.BlobContainer)

Aggregations

RepositoryMetadata (org.elasticsearch.cluster.metadata.RepositoryMetadata)6 BlobStoreRepository (org.elasticsearch.repositories.blobstore.BlobStoreRepository)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 BlobContainer (org.elasticsearch.common.blobstore.BlobContainer)5 InputStream (java.io.InputStream)1 ClusterService (org.elasticsearch.cluster.service.ClusterService)1 SnapshotId (org.elasticsearch.snapshots.SnapshotId)1 SnapshotInfo (org.elasticsearch.snapshots.SnapshotInfo)1