Search in sources :

Example 51 with RepositoryMetadata

use of org.elasticsearch.cluster.metadata.RepositoryMetadata in project crate by crate.

the class MockEventuallyConsistentRepositoryTests method testReadAfterWriteAfterReadThrows.

public void testReadAfterWriteAfterReadThrows() 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);
        expectThrows(NoSuchFileException.class, () -> blobContainer.readBlob(blobName));
        blobContainer.writeBlob(blobName, new ByteArrayInputStream(blobData), lengthWritten, true);
        assertThrowsOnInconsistentRead(blobContainer, blobName);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BlobStoreRepository(org.elasticsearch.repositories.blobstore.BlobStoreRepository) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) BlobContainer(org.elasticsearch.common.blobstore.BlobContainer)

Example 52 with RepositoryMetadata

use of org.elasticsearch.cluster.metadata.RepositoryMetadata in project crate by crate.

the class MockEventuallyConsistentRepositoryTests method testReadAfterDeleteAfterWriteThrows.

public void testReadAfterDeleteAfterWriteThrows() 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);
        blobContainer.deleteBlobsIgnoringIfNotExists(Collections.singletonList(blobName));
        assertThrowsOnInconsistentRead(blobContainer, blobName);
        blobStoreContext.forceConsistent();
        expectThrows(NoSuchFileException.class, () -> blobContainer.readBlob(blobName));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BlobStoreRepository(org.elasticsearch.repositories.blobstore.BlobStoreRepository) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) BlobContainer(org.elasticsearch.common.blobstore.BlobContainer)

Example 53 with RepositoryMetadata

use of org.elasticsearch.cluster.metadata.RepositoryMetadata 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)29 RepositoryMetaData (org.elasticsearch.cluster.metadata.RepositoryMetaData)24 ClusterState (org.elasticsearch.cluster.ClusterState)13 RepositoriesMetadata (org.elasticsearch.cluster.metadata.RepositoriesMetadata)13 ArrayList (java.util.ArrayList)11 Settings (org.elasticsearch.common.settings.Settings)11 RepositoriesMetaData (org.elasticsearch.cluster.metadata.RepositoriesMetaData)10 IOException (java.io.IOException)8 ClusterName (org.elasticsearch.cluster.ClusterName)8 Before (org.junit.Before)7 HashMap (java.util.HashMap)6 BlobStoreRepository (org.elasticsearch.repositories.blobstore.BlobStoreRepository)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)5 ActionListener (org.elasticsearch.action.ActionListener)5 BlobContainer (org.elasticsearch.common.blobstore.BlobContainer)5 RepositoryException (org.elasticsearch.repositories.RepositoryException)5 Test (org.junit.Test)5 List (java.util.List)4 Map (java.util.Map)4