use of org.elasticsearch.cluster.metadata.RepositoryMetaData in project crate by crate.
the class SysSnapshotsTest method testUnavailableSnapshotsAreFilteredOut.
@Test
public void testUnavailableSnapshotsAreFilteredOut() throws Exception {
HashMap<String, SnapshotId> snapshots = new HashMap<>();
SnapshotId s1 = new SnapshotId("s1", UUIDs.randomBase64UUID());
SnapshotId s2 = new SnapshotId("s2", UUIDs.randomBase64UUID());
snapshots.put(s1.getUUID(), s1);
snapshots.put(s2.getUUID(), s2);
RepositoryData repositoryData = new RepositoryData(1, snapshots, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), ShardGenerations.EMPTY);
Repository r1 = mock(Repository.class);
doAnswer((Answer<Void>) invocation -> {
ActionListener<RepositoryData> callback = invocation.getArgument(0);
callback.onResponse(repositoryData);
return null;
}).when(r1).getRepositoryData(any());
when(r1.getMetadata()).thenReturn(new RepositoryMetadata("repo1", "fs", Settings.EMPTY));
doAnswer((Answer<Void>) invocation -> {
ActionListener<SnapshotInfo> callback = invocation.getArgument(1);
callback.onFailure(new SnapshotException("repo1", "s1", "Everything is wrong"));
return null;
}).when(r1).getSnapshotInfo(eq(s1), any());
doAnswer((Answer<Void>) invocation -> {
ActionListener<SnapshotInfo> callback = invocation.getArgument(1);
callback.onResponse(new SnapshotInfo(s2, Collections.emptyList(), SnapshotState.SUCCESS));
return null;
}).when(r1).getSnapshotInfo(eq(s2), any());
SysSnapshots sysSnapshots = new SysSnapshots(() -> Collections.singletonList(r1));
Stream<SysSnapshot> currentSnapshots = StreamSupport.stream(Spliterators.spliteratorUnknownSize(sysSnapshots.currentSnapshots().get().iterator(), Spliterator.ORDERED), false);
assertThat(currentSnapshots.map(SysSnapshot::name).collect(Collectors.toList()), containsInAnyOrder("s1", "s2"));
}
use of org.elasticsearch.cluster.metadata.RepositoryMetaData in project crate by crate.
the class BlobStoreRepositoryRestoreTests method createRepository.
/**
* Create a {@link Repository} with a random name *
*/
private Repository createRepository() {
Settings settings = Settings.builder().put("location", randomAlphaOfLength(10)).build();
RepositoryMetadata repositoryMetadata = new RepositoryMetadata(randomAlphaOfLength(10), FsRepository.TYPE, settings);
final ClusterService clusterService = BlobStoreTestUtil.mockClusterService(repositoryMetadata);
final FsRepository repository = new FsRepository(repositoryMetadata, createEnvironment(), xContentRegistry(), clusterService) {
@Override
protected void assertSnapshotOrGenericThread() {
// eliminate thread name check as we create repo manually
}
};
clusterService.addStateApplier(event -> repository.updateState(event.state()));
// Apply state once to initialize repo properly like RepositoriesService would
repository.updateState(clusterService.state());
repository.start();
return repository;
}
use of org.elasticsearch.cluster.metadata.RepositoryMetaData in project crate by crate.
the class RepositoriesMetadataSerializationTests method createTestInstance.
@Override
protected Custom createTestInstance() {
int numberOfRepositories = randomInt(10);
List<RepositoryMetadata> entries = new ArrayList<>();
for (int i = 0; i < numberOfRepositories; i++) {
// divide by 2 to not overflow when adding to this number for the pending generation below
final long generation = randomNonNegativeLong() / 2L;
entries.add(new RepositoryMetadata(randomAlphaOfLength(10), randomAlphaOfLength(10), randomSettings(), generation, generation + randomLongBetween(0, generation)));
}
entries.sort(Comparator.comparing(RepositoryMetadata::name));
return new RepositoriesMetadata(entries);
}
use of org.elasticsearch.cluster.metadata.RepositoryMetaData in project crate by crate.
the class RepositoriesMetadataSerializationTests method doParseInstance.
@Override
protected Custom doParseInstance(XContentParser parser) throws IOException {
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
RepositoriesMetadata repositoriesMetadata = RepositoriesMetadata.fromXContent(parser);
assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
List<RepositoryMetadata> repos = new ArrayList<>(repositoriesMetadata.repositories());
repos.sort(Comparator.comparing(RepositoryMetadata::name));
return new RepositoriesMetadata(repos);
}
use of org.elasticsearch.cluster.metadata.RepositoryMetaData in project crate by crate.
the class MockEventuallyConsistentRepositoryTests method testOverwriteRandomBlobFails.
public void testOverwriteRandomBlobFails() 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 container = repository.blobStore().blobContainer(repository.basePath());
final String blobName = randomAlphaOfLength(10);
final int lengthWritten = randomIntBetween(1, 100);
final byte[] blobData = randomByteArrayOfLength(lengthWritten);
container.writeBlob(blobName, new ByteArrayInputStream(blobData), lengthWritten, false);
final AssertionError assertionError = expectThrows(AssertionError.class, () -> container.writeBlob(blobName, new ByteArrayInputStream(blobData), lengthWritten - 1, false));
assertThat(assertionError.getMessage(), startsWith("Tried to overwrite blob [" + blobName + "]"));
}
}
Aggregations