@Override protected void configure() { IndexShard shard = mock(IndexShard.class); bind(IndexShard.class).toInstance(shard); when(shard.shardId()).thenReturn(shardId); Index index = new Index(TEST_TABLE_NAME); bind(Index.class).toInstance(index); bind(ShardId.class).toInstance(shardId); MapBinder<ReferenceIdent, ShardReferenceImplementation> binder = MapBinder.newMapBinder( binder(), ReferenceIdent.class, ShardReferenceImplementation.class); binder .addBinding(SysShardsTableInfo.INFOS.get(new ColumnIdent("id")).ident()) .toInstance(shardIdExpression); bind(ShardReferenceResolver.class).asEagerSingleton(); bind(AllocationDecider.class).to(DiskThresholdDecider.class); bind(ShardCollectService.class).asEagerSingleton(); bind(DiscoveryService.class).toInstance(discoveryService); // blob stuff MapBinder<ReferenceIdent, BlobShardReferenceImplementation> blobBinder = MapBinder.newMapBinder( binder(), ReferenceIdent.class, BlobShardReferenceImplementation.class); bind(Settings.class).annotatedWith(IndexSettings.class).toInstance(ImmutableSettings.EMPTY); }
@Override protected void bindExtensions(Binder binder) { MapBinder<K, V> mapBinder = MapBinder.newMapBinder(binder, keyType, valueType); for (Map.Entry<K, V> entry : map.entrySet()) { mapBinder.addBinding(entry.getKey()).toInstance(entry.getValue()); } }
@Override protected final void bindExtensions(Binder binder) { MapBinder<String, T> parserMapBinder = MapBinder.newMapBinder(binder, String.class, extensionClass); for (Map.Entry<String, Class<? extends T>> clazz : extensions.entrySet()) { parserMapBinder.addBinding(clazz.getKey()).to(clazz.getValue()); } }
public void processXContentQueryParser( String name, Class<? extends QueryParser> xcontentQueryParser) { if (!groupSettings.containsKey(name)) { binder .addBinding(name) .toProvider(FactoryProvider.newFactory(QueryParserFactory.class, xcontentQueryParser)) .in(Scopes.SINGLETON); } }
@Override protected void configure() { registerAction(NodesInfoAction.INSTANCE, TransportNodesInfoAction.class); registerAction(NodesStatsAction.INSTANCE, TransportNodesStatsAction.class); registerAction(NodesShutdownAction.INSTANCE, TransportNodesShutdownAction.class); registerAction(NodesRestartAction.INSTANCE, TransportNodesRestartAction.class); registerAction(NodesHotThreadsAction.INSTANCE, TransportNodesHotThreadsAction.class); registerAction(ClusterStateAction.INSTANCE, TransportClusterStateAction.class); registerAction(ClusterHealthAction.INSTANCE, TransportClusterHealthAction.class); registerAction( ClusterUpdateSettingsAction.INSTANCE, TransportClusterUpdateSettingsAction.class); registerAction(ClusterRerouteAction.INSTANCE, TransportClusterRerouteAction.class); registerAction(ClusterSearchShardsAction.INSTANCE, TransportClusterSearchShardsAction.class); registerAction(PendingClusterTasksAction.INSTANCE, TransportPendingClusterTasksAction.class); registerAction(IndicesStatsAction.INSTANCE, TransportIndicesStatsAction.class); registerAction(IndicesStatusAction.INSTANCE, TransportIndicesStatusAction.class); registerAction(IndicesSegmentsAction.INSTANCE, TransportIndicesSegmentsAction.class); registerAction(CreateIndexAction.INSTANCE, TransportCreateIndexAction.class); registerAction(DeleteIndexAction.INSTANCE, TransportDeleteIndexAction.class); registerAction(OpenIndexAction.INSTANCE, TransportOpenIndexAction.class); registerAction(CloseIndexAction.INSTANCE, TransportCloseIndexAction.class); registerAction(IndicesExistsAction.INSTANCE, TransportIndicesExistsAction.class); registerAction(TypesExistsAction.INSTANCE, TransportTypesExistsAction.class); registerAction(GetMappingsAction.INSTANCE, TransportGetMappingsAction.class); registerAction(GetFieldMappingsAction.INSTANCE, TransportGetFieldMappingsAction.class); registerAction(PutMappingAction.INSTANCE, TransportPutMappingAction.class); registerAction(DeleteMappingAction.INSTANCE, TransportDeleteMappingAction.class); registerAction(IndicesAliasesAction.INSTANCE, TransportIndicesAliasesAction.class); registerAction(UpdateSettingsAction.INSTANCE, TransportUpdateSettingsAction.class); registerAction(AnalyzeAction.INSTANCE, TransportAnalyzeAction.class); registerAction(PutIndexTemplateAction.INSTANCE, TransportPutIndexTemplateAction.class); registerAction(GetIndexTemplatesAction.INSTANCE, TransportGetIndexTemplatesAction.class); registerAction(DeleteIndexTemplateAction.INSTANCE, TransportDeleteIndexTemplateAction.class); registerAction(ValidateQueryAction.INSTANCE, TransportValidateQueryAction.class); registerAction(GatewaySnapshotAction.INSTANCE, TransportGatewaySnapshotAction.class); registerAction(RefreshAction.INSTANCE, TransportRefreshAction.class); registerAction(FlushAction.INSTANCE, TransportFlushAction.class); registerAction(OptimizeAction.INSTANCE, TransportOptimizeAction.class); registerAction(ClearIndicesCacheAction.INSTANCE, TransportClearIndicesCacheAction.class); registerAction(PutWarmerAction.INSTANCE, TransportPutWarmerAction.class); registerAction(DeleteWarmerAction.INSTANCE, TransportDeleteWarmerAction.class); registerAction(GetWarmersAction.INSTANCE, TransportGetWarmersAction.class); registerAction(GetAliasesAction.INSTANCE, TransportGetAliasesAction.class); registerAction(AliasesExistAction.INSTANCE, TransportAliasesExistAction.class); registerAction(IndexAction.INSTANCE, TransportIndexAction.class); registerAction(GetAction.INSTANCE, TransportGetAction.class); registerAction(TermVectorAction.INSTANCE, TransportSingleShardTermVectorAction.class); registerAction( MultiTermVectorsAction.INSTANCE, TransportMultiTermVectorsAction.class, TransportSingleShardMultiTermsVectorAction.class); registerAction( DeleteAction.INSTANCE, TransportDeleteAction.class, TransportIndexDeleteAction.class, TransportShardDeleteAction.class); registerAction(CountAction.INSTANCE, TransportCountAction.class); registerAction(SuggestAction.INSTANCE, TransportSuggestAction.class); registerAction(UpdateAction.INSTANCE, TransportUpdateAction.class); registerAction( MultiGetAction.INSTANCE, TransportMultiGetAction.class, TransportShardMultiGetAction.class); registerAction(BulkAction.INSTANCE, TransportBulkAction.class, TransportShardBulkAction.class); registerAction( DeleteByQueryAction.INSTANCE, TransportDeleteByQueryAction.class, TransportIndexDeleteByQueryAction.class, TransportShardDeleteByQueryAction.class); registerAction( SearchAction.INSTANCE, TransportSearchAction.class, TransportSearchDfsQueryThenFetchAction.class, TransportSearchQueryThenFetchAction.class, TransportSearchDfsQueryAndFetchAction.class, TransportSearchQueryAndFetchAction.class, TransportSearchScanAction.class); registerAction( SearchScrollAction.INSTANCE, TransportSearchScrollAction.class, TransportSearchScrollScanAction.class, TransportSearchScrollQueryThenFetchAction.class, TransportSearchScrollQueryAndFetchAction.class); registerAction(MultiSearchAction.INSTANCE, TransportMultiSearchAction.class); registerAction(MoreLikeThisAction.INSTANCE, TransportMoreLikeThisAction.class); registerAction(PercolateAction.INSTANCE, TransportPercolateAction.class); registerAction( MultiPercolateAction.INSTANCE, TransportMultiPercolateAction.class, TransportShardMultiPercolateAction.class); registerAction(ExplainAction.INSTANCE, TransportExplainAction.class); registerAction(ClearScrollAction.INSTANCE, TransportClearScrollAction.class); // register Name -> GenericAction Map that can be injected to instances. MapBinder<String, GenericAction> actionsBinder = MapBinder.newMapBinder(binder(), String.class, GenericAction.class); for (Map.Entry<String, ActionEntry> entry : actions.entrySet()) { actionsBinder.addBinding(entry.getKey()).toInstance(entry.getValue().action); } // register GenericAction -> transportAction Map that can be injected to instances. // also register any supporting classes if (!proxy) { MapBinder<GenericAction, TransportAction> transportActionsBinder = MapBinder.newMapBinder(binder(), GenericAction.class, TransportAction.class); for (Map.Entry<String, ActionEntry> entry : actions.entrySet()) { // bind the action as eager singleton, so the map binder one will reuse it bind(entry.getValue().transportAction).asEagerSingleton(); transportActionsBinder .addBinding(entry.getValue().action) .to(entry.getValue().transportAction) .asEagerSingleton(); for (Class supportAction : entry.getValue().supportTransportActions) { bind(supportAction).asEagerSingleton(); } } } }
@Override protected void configure() { functionBinder = MapBinder.newMapBinder(binder(), FunctionIdent.class, FunctionImplementation.class); functionBinder.addBinding(TestFunction.ident).toInstance(new TestFunction()); bind(Functions.class).asEagerSingleton(); bind(ReferenceInfos.class).toInstance(mock(ReferenceInfos.class)); bind(ThreadPool.class).toInstance(testThreadPool); BulkRetryCoordinator bulkRetryCoordinator = mock(BulkRetryCoordinator.class); BulkRetryCoordinatorPool bulkRetryCoordinatorPool = mock(BulkRetryCoordinatorPool.class); when(bulkRetryCoordinatorPool.coordinator(any(ShardId.class))) .thenReturn(bulkRetryCoordinator); bind(BulkRetryCoordinatorPool.class).toInstance(bulkRetryCoordinatorPool); bind(TransportBulkCreateIndicesAction.class) .toInstance(mock(TransportBulkCreateIndicesAction.class)); bind(CircuitBreakerService.class).toInstance(new NoneCircuitBreakerService()); bind(ActionFilters.class).toInstance(mock(ActionFilters.class)); bind(ScriptService.class).toInstance(mock(ScriptService.class)); bind(SearchService.class).toInstance(mock(InternalSearchService.class)); bind(AllocationService.class).toInstance(mock(AllocationService.class)); bind(MetaDataCreateIndexService.class).toInstance(mock(MetaDataCreateIndexService.class)); bind(DynamicSettings.class) .annotatedWith(ClusterDynamicSettings.class) .toInstance(mock(DynamicSettings.class)); bind(MetaDataDeleteIndexService.class).toInstance(mock(MetaDataDeleteIndexService.class)); bind(ClusterInfoService.class).toInstance(mock(ClusterInfoService.class)); bind(TransportService.class).toInstance(mock(TransportService.class)); bind(MapperService.class).toInstance(mock(MapperService.class)); OsService osService = mock(OsService.class); OsStats osStats = mock(OsStats.class); when(osService.stats()).thenReturn(osStats); OsStats.Cpu osCpu = mock(OsStats.Cpu.class); when(osCpu.stolen()).thenReturn((short) 1); when(osStats.cpu()).thenReturn(osCpu); bind(OsService.class).toInstance(osService); bind(NodeService.class).toInstance(mock(NodeService.class)); bind(Discovery.class).toInstance(mock(Discovery.class)); bind(NetworkService.class).toInstance(mock(NetworkService.class)); bind(TransportShardBulkAction.class).toInstance(mock(TransportShardBulkAction.class)); bind(TransportCreateIndexAction.class).toInstance(mock(TransportCreateIndexAction.class)); discoveryService = mock(DiscoveryService.class); DiscoveryNode discoveryNode = mock(DiscoveryNode.class); when(discoveryNode.id()).thenReturn(TEST_NODE_ID); when(discoveryService.localNode()).thenReturn(discoveryNode); ClusterService clusterService = mock(ClusterService.class); ClusterState state = mock(ClusterState.class); DiscoveryNodes discoveryNodes = mock(DiscoveryNodes.class); when(discoveryNodes.localNodeId()).thenReturn(TEST_NODE_ID); when(state.nodes()).thenReturn(discoveryNodes); when(clusterService.state()).thenReturn(state); when(clusterService.localNode()).thenReturn(discoveryNode); bind(ClusterService.class).toInstance(clusterService); IndicesService indicesService = mock(IndicesService.class); bind(IndicesService.class).toInstance(indicesService); bind(Settings.class).toInstance(ImmutableSettings.EMPTY); bind(MetaDataUpdateSettingsService.class) .toInstance(mock(MetaDataUpdateSettingsService.class)); bind(Client.class).toInstance(mock(Client.class)); Provider<TransportCreateIndexAction> transportCreateIndexActionProvider = mock(Provider.class); when(transportCreateIndexActionProvider.get()) .thenReturn(mock(TransportCreateIndexAction.class)); Provider<TransportDeleteIndexAction> transportDeleteActionProvider = mock(Provider.class); when(transportDeleteActionProvider.get()).thenReturn(mock(TransportDeleteIndexAction.class)); Provider<TransportUpdateSettingsAction> transportUpdateSettingsActionProvider = mock(Provider.class); when(transportUpdateSettingsActionProvider.get()) .thenReturn(mock(TransportUpdateSettingsAction.class)); BlobIndices blobIndices = new BlobIndices( ImmutableSettings.EMPTY, transportCreateIndexActionProvider, transportDeleteActionProvider, transportUpdateSettingsActionProvider, indicesService, mock(IndicesLifecycle.class), mock(BlobEnvironment.class), clusterService); bind(BlobIndices.class).toInstance(blobIndices); bind(ReferenceResolver.class).to(GlobalReferenceResolver.class); TransportPutIndexTemplateAction transportPutIndexTemplateAction = mock(TransportPutIndexTemplateAction.class); bind(TransportPutIndexTemplateAction.class).toInstance(transportPutIndexTemplateAction); bind(IndexService.class).toInstance(indexService); }
@Override protected void configure() { bind(IndexQueryParserService.class).asEagerSingleton(); // handle XContenQueryParsers MapBinder<String, QueryParserFactory> queryBinder = MapBinder.newMapBinder(binder(), String.class, QueryParserFactory.class); Map<String, Settings> xContentQueryParserGroups = settings.getGroups(IndexQueryParserService.Defaults.QUERY_PREFIX); for (Map.Entry<String, Settings> entry : xContentQueryParserGroups.entrySet()) { String qName = entry.getKey(); Settings qSettings = entry.getValue(); Class<? extends QueryParser> type = qSettings.getAsClass("type", null); if (type == null) { throw new IllegalArgumentException( "Query Parser [" + qName + "] must be provided with a type"); } queryBinder .addBinding(qName) .toProvider( FactoryProvider.newFactory( QueryParserFactory.class, qSettings.getAsClass("type", null))) .in(Scopes.SINGLETON); } QueryParsersProcessor.XContentQueryParsersBindings xContentQueryParsersBindings = new QueryParsersProcessor.XContentQueryParsersBindings( queryBinder, xContentQueryParserGroups); for (QueryParsersProcessor processor : processors) { processor.processXContentQueryParsers(xContentQueryParsersBindings); } for (Map.Entry<String, Class<? extends QueryParser>> entry : queries.entrySet()) { queryBinder .addBinding(entry.getKey()) .toProvider(FactoryProvider.newFactory(QueryParserFactory.class, entry.getValue())) .in(Scopes.SINGLETON); } // handle XContentFilterParsers MapBinder<String, FilterParserFactory> filterBinder = MapBinder.newMapBinder(binder(), String.class, FilterParserFactory.class); Map<String, Settings> xContentFilterParserGroups = settings.getGroups(IndexQueryParserService.Defaults.FILTER_PREFIX); for (Map.Entry<String, Settings> entry : xContentFilterParserGroups.entrySet()) { String fName = entry.getKey(); Settings fSettings = entry.getValue(); Class<? extends FilterParser> type = fSettings.getAsClass("type", null); if (type == null) { throw new IllegalArgumentException( "Filter Parser [" + fName + "] must be provided with a type"); } filterBinder .addBinding(fName) .toProvider( FactoryProvider.newFactory( FilterParserFactory.class, fSettings.getAsClass("type", null))) .in(Scopes.SINGLETON); } QueryParsersProcessor.XContentFilterParsersBindings xContentFilterParsersBindings = new QueryParsersProcessor.XContentFilterParsersBindings( filterBinder, xContentFilterParserGroups); for (QueryParsersProcessor processor : processors) { processor.processXContentFilterParsers(xContentFilterParsersBindings); } for (Map.Entry<String, Class<? extends FilterParser>> entry : filters.entrySet()) { filterBinder .addBinding(entry.getKey()) .toProvider(FactoryProvider.newFactory(FilterParserFactory.class, entry.getValue())) .in(Scopes.SINGLETON); } }