use of org.elasticsearch.indices.IndicesService in project crate by crate.
the class TransportShardUpsertActionTest method prepare.
@Before
public void prepare() throws Exception {
charactersIndexUUID = UUIDs.randomBase64UUID();
partitionIndexUUID = UUIDs.randomBase64UUID();
IndicesService indicesService = mock(IndicesService.class);
IndexService indexService = mock(IndexService.class);
Index charactersIndex = new Index(TABLE_IDENT.indexNameOrAlias(), charactersIndexUUID);
Index partitionIndex = new Index(PARTITION_INDEX, partitionIndexUUID);
when(indicesService.indexServiceSafe(charactersIndex)).thenReturn(indexService);
when(indicesService.indexServiceSafe(partitionIndex)).thenReturn(indexService);
indexShard = mock(IndexShard.class);
when(indexService.getShard(0)).thenReturn(indexShard);
// Avoid null pointer exceptions
DocTableInfo tableInfo = mock(DocTableInfo.class);
Schemas schemas = mock(Schemas.class);
when(tableInfo.columns()).thenReturn(Collections.<Reference>emptyList());
when(schemas.getTableInfo(any(RelationName.class), eq(Operation.INSERT))).thenReturn(tableInfo);
transportShardUpsertAction = new TestingTransportShardUpsertAction(mock(ThreadPool.class), clusterService, MockTransportService.createNewService(Settings.EMPTY, Version.V_3_2_0, THREAD_POOL, clusterService.getClusterSettings()), mock(SchemaUpdateClient.class), mock(TasksService.class), indicesService, mock(ShardStateAction.class), createNodeContext(), schemas);
}
use of org.elasticsearch.indices.IndicesService in project crate by crate.
the class TransportReplicationAllPermitsAcquisitionTests method mockIndicesService.
private static IndicesService mockIndicesService(ShardId shardId, SetOnce<Boolean> executedOnPrimary, IndexShard primary, IndexShard replica) {
final IndexService indexService = mock(IndexService.class);
when(indexService.getShard(shardId.id())).then(invocation -> (executedOnPrimary.get() == null) ? primary : replica);
final IndicesService indicesService = mock(IndicesService.class);
when(indicesService.indexServiceSafe(shardId.getIndex())).then(invocation -> indexService);
return indicesService;
}
use of org.elasticsearch.indices.IndicesService in project crate by crate.
the class ClusterInfoServiceIT method testClusterInfoServiceCollectsInformation.
public void testClusterInfoServiceCollectsInformation() throws Exception {
internalCluster().startNodes(2);
assertAcked(prepareCreate("test").setSettings(Settings.builder().put(Store.INDEX_STORE_STATS_REFRESH_INTERVAL_SETTING.getKey(), 0).put(IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1).put(EnableAllocationDecider.INDEX_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), EnableAllocationDecider.Rebalance.NONE).build()));
ensureGreen("test");
InternalTestCluster internalTestCluster = internalCluster();
// Get the cluster info service on the master node
final InternalClusterInfoService infoService = (InternalClusterInfoService) internalTestCluster.getInstance(ClusterInfoService.class, internalTestCluster.getMasterName());
infoService.setUpdateFrequency(TimeValue.timeValueMillis(200));
infoService.onMaster();
ClusterInfo info = infoService.refresh();
assertNotNull("info should not be null", info);
ImmutableOpenMap<String, DiskUsage> leastUsages = info.getNodeLeastAvailableDiskUsages();
ImmutableOpenMap<String, DiskUsage> mostUsages = info.getNodeMostAvailableDiskUsages();
ImmutableOpenMap<String, Long> shardSizes = info.shardSizes;
assertNotNull(leastUsages);
assertNotNull(shardSizes);
assertThat("some usages are populated", leastUsages.values().size(), Matchers.equalTo(2));
assertThat("some shard sizes are populated", shardSizes.values().size(), greaterThan(0));
for (ObjectCursor<DiskUsage> usage : leastUsages.values()) {
logger.info("--> usage: {}", usage.value);
assertThat("usage has be retrieved", usage.value.getFreeBytes(), greaterThan(0L));
}
for (ObjectCursor<DiskUsage> usage : mostUsages.values()) {
logger.info("--> usage: {}", usage.value);
assertThat("usage has be retrieved", usage.value.getFreeBytes(), greaterThan(0L));
}
for (ObjectCursor<Long> size : shardSizes.values()) {
logger.info("--> shard size: {}", size.value);
assertThat("shard size is greater than 0", size.value, greaterThanOrEqualTo(0L));
}
ClusterService clusterService = internalTestCluster.getInstance(ClusterService.class, internalTestCluster.getMasterName());
ClusterState state = clusterService.state();
for (ShardRouting shard : state.routingTable().allShards()) {
String dataPath = info.getDataPath(shard);
assertNotNull(dataPath);
String nodeId = shard.currentNodeId();
DiscoveryNode discoveryNode = state.getNodes().get(nodeId);
IndicesService indicesService = internalTestCluster.getInstance(IndicesService.class, discoveryNode.getName());
IndexService indexService = indicesService.indexService(shard.index());
IndexShard indexShard = indexService.getShardOrNull(shard.id());
assertEquals(indexShard.shardPath().getRootDataPath().toString(), dataPath);
}
}
use of org.elasticsearch.indices.IndicesService in project crate by crate.
the class GlobalCheckpointSyncIT method testPersistGlobalCheckpoint.
public void testPersistGlobalCheckpoint() throws Exception {
internalCluster().ensureAtLeastNumDataNodes(2);
if (randomBoolean()) {
execute("create table test(id integer) clustered into 1 shards with" + "(\"global_checkpoint_sync.interval\" = ?, \"translog.durability\" = 'ASYNC', number_of_replicas = ?, \"translog.sync_interval\" = ?)", new Object[] { randomTimeValue(100, 1000, "ms"), randomIntBetween(0, 1), randomTimeValue(100, 1000, "ms") });
} else {
execute("create table test(id integer) clustered into 1 shards with" + "(\"global_checkpoint_sync.interval\" = ?, number_of_replicas = ?)", new Object[] { randomTimeValue(100, 1000, "ms"), randomIntBetween(0, 1) });
}
if (randomBoolean()) {
ensureGreen(getFqn("test"));
}
int numDocs = randomIntBetween(1, 20);
for (int i = 0; i < numDocs; i++) {
execute("insert into test(id) values(?)", new Object[] { i });
}
ensureGreen(getFqn("test"));
assertBusy(() -> {
for (IndicesService indicesService : internalCluster().getDataNodeInstances(IndicesService.class)) {
for (IndexService indexService : indicesService) {
for (IndexShard shard : indexService) {
final SeqNoStats seqNoStats = shard.seqNoStats();
assertThat(seqNoStats.getLocalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
assertThat(shard.getLastKnownGlobalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
assertThat(shard.getLastSyncedGlobalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
}
}
}
});
}
use of org.elasticsearch.indices.IndicesService in project crate by crate.
the class RetentionLeaseBackgroundSyncActionTests method testRetentionLeaseBackgroundSyncActionOnPrimary.
@Test
public void testRetentionLeaseBackgroundSyncActionOnPrimary() throws Throwable {
final IndicesService indicesService = mock(IndicesService.class);
final Index index = new Index("index", "uuid");
final IndexService indexService = mock(IndexService.class);
when(indicesService.indexServiceSafe(index)).thenReturn(indexService);
final int id = randomIntBetween(0, 4);
final IndexShard indexShard = mock(IndexShard.class);
when(indexService.getShard(id)).thenReturn(indexShard);
final ShardId shardId = new ShardId(index, id);
when(indexShard.shardId()).thenReturn(shardId);
final RetentionLeaseBackgroundSyncAction action = new RetentionLeaseBackgroundSyncAction(transportService, clusterService, indicesService, threadPool, shardStateAction);
final RetentionLeases retentionLeases = mock(RetentionLeases.class);
final RetentionLeaseBackgroundSyncAction.Request request = new RetentionLeaseBackgroundSyncAction.Request(indexShard.shardId(), retentionLeases);
final CountDownLatch latch = new CountDownLatch(1);
action.shardOperationOnPrimary(request, indexShard, new LatchedActionListener<>(ActionTestUtils.assertNoFailureListener(result -> {
// the retention leases on the shard should be persisted
verify(indexShard).persistRetentionLeases();
// we should forward the request containing the current retention leases to the replica
assertThat(result.replicaRequest(), sameInstance(request));
}), latch));
latch.await();
}
Aggregations