コード例 #1
0
 @Override
 public DiscoveryNode localNode() {
   return discoveryService.localNode();
 }
コード例 #2
0
  @Test
  public void testFileUriCollect() throws Exception {
    ClusterService clusterService = mock(ClusterService.class);
    DiscoveryNode discoveryNode = mock(DiscoveryNode.class);
    when(discoveryNode.id()).thenReturn("dummyNodeId");
    DiscoveryNodes discoveryNodes = mock(DiscoveryNodes.class);
    when(discoveryNodes.localNodeId()).thenReturn("dummyNodeId");
    ClusterState clusterState = mock(ClusterState.class);
    when(clusterState.nodes()).thenReturn(discoveryNodes);
    when(clusterService.state()).thenReturn(clusterState);
    DiscoveryService discoveryService = mock(DiscoveryService.class);
    when(discoveryService.localNode()).thenReturn(discoveryNode);
    IndicesService indicesService = mock(IndicesService.class);
    Functions functions =
        new Functions(
            ImmutableMap.<FunctionIdent, FunctionImplementation>of(),
            ImmutableMap.<String, DynamicFunctionResolver>of());
    ReferenceResolver referenceResolver =
        new ReferenceResolver() {
          @Override
          public ReferenceImplementation getImplementation(ReferenceIdent ident) {
            return null;
          }
        };

    NodeSettingsService nodeSettingsService = mock(NodeSettingsService.class);

    MapSideDataCollectOperation collectOperation =
        new MapSideDataCollectOperation(
            clusterService,
            ImmutableSettings.EMPTY,
            mock(TransportActionProvider.class, Answers.RETURNS_DEEP_STUBS.get()),
            mock(BulkRetryCoordinatorPool.class),
            functions,
            referenceResolver,
            mock(NodeSysExpression.class),
            indicesService,
            new ThreadPool(
                ImmutableSettings.builder().put("name", getClass().getName()).build(), null),
            new CollectServiceResolver(
                discoveryService,
                new SystemCollectService(
                    discoveryService,
                    functions,
                    new StatsTables(ImmutableSettings.EMPTY, nodeSettingsService))),
            mock(InformationSchemaCollectService.class),
            mock(UnassignedShardsCollectService.class));

    File tmpFile = temporaryFolder.newFile("fileUriCollectOperation.json");
    try (FileWriter writer = new FileWriter(tmpFile)) {
      writer.write("{\"name\": \"Arthur\", \"id\": 4, \"details\": {\"age\": 38}}\n");
      writer.write("{\"id\": 5, \"name\": \"Trillian\", \"details\": {\"age\": 33}}\n");
    }

    Routing routing =
        new Routing(
            TreeMapBuilder.<String, Map<String, List<Integer>>>newMapBuilder()
                .put("dummyNodeId", new TreeMap<String, List<Integer>>())
                .map());
    FileUriCollectPhase collectNode =
        new FileUriCollectPhase(
            UUID.randomUUID(),
            0,
            "test",
            routing,
            Literal.newLiteral(Paths.get(tmpFile.toURI()).toUri().toString()),
            Arrays.<Symbol>asList(
                createReference("name", DataTypes.STRING),
                createReference(new ColumnIdent("details", "age"), DataTypes.INTEGER)),
            Arrays.<Projection>asList(),
            null,
            false);
    CollectingProjector cd = new CollectingProjector();
    cd.startProjection(mock(ExecutionState.class));
    collectOperation.collect(collectNode, cd, mock(JobCollectContext.class));
    assertThat(cd.result().get(), contains(isRow("Arthur", 38), isRow("Trillian", 33)));
  }