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);
}
}
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));
}
}
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));
}
}
}
Aggregations