Пример #1
0
  @Test
  public void testWrongRouting() throws Exception {

    expectedException.expect(UnhandledServerException.class);
    expectedException.expectMessage("unsupported routing");

    CollectPhase collectNode =
        new CollectPhase(
            UUID.randomUUID(),
            0,
            "wrong",
            new Routing(
                TreeMapBuilder.<String, Map<String, List<Integer>>>newMapBuilder()
                    .put(
                        "bla",
                        TreeMapBuilder.<String, List<Integer>>newMapBuilder()
                            .put("my_index", Arrays.asList(1))
                            .put("my_index", Arrays.asList(1))
                            .map())
                    .map()),
            ImmutableList.<Symbol>of(),
            EMPTY_PROJECTIONS);
    collectNode.maxRowGranularity(RowGranularity.DOC);
    operation.collect(collectNode, new CollectingProjector(), null);
  }
Пример #2
0
 private Bucket getBucket(CollectPhase collectNode)
     throws InterruptedException, ExecutionException {
   CollectingProjector cd = new CollectingProjector();
   JobExecutionContext.Builder builder = jobContextService.newBuilder(collectNode.jobId());
   JobCollectContext jobCollectContext =
       new JobCollectContext(
           collectNode.jobId(), collectNode, operation, RAM_ACCOUNTING_CONTEXT, cd);
   builder.addSubContext(collectNode.executionPhaseId(), jobCollectContext);
   JobExecutionContext context = jobContextService.createContext(builder);
   cd.startProjection(jobCollectContext);
   operation.collect(collectNode, cd, jobCollectContext);
   return cd.result().get();
 }
  @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)));
  }