use of org.elasticsearch.cluster.service.ClusterApplierService in project crate by crate.
the class BlobStoreTestUtil method mockClusterService.
private static ClusterService mockClusterService(ClusterState initialState) {
final ThreadPool threadPool = mock(ThreadPool.class);
when(threadPool.executor(ThreadPool.Names.SNAPSHOT)).thenReturn(new SameThreadExecutorService());
when(threadPool.generic()).thenReturn(new SameThreadExecutorService());
final ClusterService clusterService = mock(ClusterService.class);
final ClusterApplierService clusterApplierService = mock(ClusterApplierService.class);
when(clusterService.getClusterApplierService()).thenReturn(clusterApplierService);
final AtomicReference<ClusterState> currentState = new AtomicReference<>(initialState);
when(clusterService.state()).then(invocationOnMock -> currentState.get());
final List<ClusterStateApplier> appliers = new CopyOnWriteArrayList<>();
doAnswer(invocation -> {
final ClusterStateUpdateTask task = ((ClusterStateUpdateTask) invocation.getArguments()[1]);
final ClusterState current = currentState.get();
final ClusterState next = task.execute(current);
currentState.set(next);
appliers.forEach(applier -> applier.applyClusterState(new ClusterChangedEvent((String) invocation.getArguments()[0], next, current)));
task.clusterStateProcessed((String) invocation.getArguments()[0], current, next);
return null;
}).when(clusterService).submitStateUpdateTask(anyString(), any(ClusterStateUpdateTask.class));
doAnswer(invocation -> {
appliers.add((ClusterStateApplier) invocation.getArguments()[0]);
return null;
}).when(clusterService).addStateApplier(any(ClusterStateApplier.class));
when(clusterApplierService.threadPool()).thenReturn(threadPool);
return clusterService;
}
use of org.elasticsearch.cluster.service.ClusterApplierService in project crate by crate.
the class CrateDummyClusterServiceUnitTest method createClusterService.
protected ClusterService createClusterService(Collection<Setting<?>> additionalClusterSettings, Version version) {
Set<Setting<?>> clusterSettingsSet = new HashSet<>(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
clusterSettingsSet.addAll(additionalClusterSettings);
ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, clusterSettingsSet);
ClusterService clusterService = new ClusterService(Settings.builder().put("cluster.name", "ClusterServiceTests").put(Node.NODE_NAME_SETTING.getKey(), NODE_NAME).build(), clusterSettings, THREAD_POOL);
clusterService.setNodeConnectionsService(createNoOpNodeConnectionsService());
DiscoveryNode discoveryNode = new DiscoveryNode(NODE_NAME, NODE_ID, buildNewFakeTransportAddress(), Collections.emptyMap(), DiscoveryNodeRole.BUILT_IN_ROLES, version);
DiscoveryNodes nodes = DiscoveryNodes.builder().add(discoveryNode).localNodeId(NODE_ID).masterNodeId(NODE_ID).build();
ClusterState clusterState = ClusterState.builder(new ClusterName(this.getClass().getSimpleName())).nodes(nodes).blocks(ClusterBlocks.EMPTY_CLUSTER_BLOCK).build();
ClusterApplierService clusterApplierService = clusterService.getClusterApplierService();
clusterApplierService.setInitialState(clusterState);
MasterService masterService = clusterService.getMasterService();
masterService.setClusterStatePublisher(createClusterStatePublisher(clusterApplierService));
masterService.setClusterStateSupplier(clusterApplierService::state);
clusterService.start();
return clusterService;
}
Aggregations