示例#1
0
  public ChannelFuture prepare(String expectedScript) throws Exception {

    if (preparedFuture != null) {
      throw new IllegalStateException("Script already prepared");
    }

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Expected script:\n" + expectedScript);
    }

    final ScriptParser parser = new Parser();
    AstScriptNode scriptAST =
        parser.parse(new ByteArrayInputStream(expectedScript.getBytes(UTF_8)));

    final ScriptValidator validator = new ScriptValidator();
    validator.validate(scriptAST);

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Parsed script:\n" + scriptAST);
    }

    RegionInfo scriptInfo = scriptAST.getRegionInfo();
    progress = new ScriptProgress(scriptInfo, expectedScript);

    final GenerateConfigurationVisitor visitor =
        new GenerateConfigurationVisitor(bootstrapFactory, addressFactory);
    configuration =
        scriptAST.accept(visitor, new GenerateConfigurationVisitor.State(barriersByName));

    preparedFuture = prepareConfiguration();

    return preparedFuture;
  }
  @Test
  public void shouldAssociateAcceptedStreamsWithAcceptStream() throws Exception {

    AstScriptNode expectedScriptNode =
        new AstScriptNodeBuilder()
            .addAcceptStream()
            .setLocation(new AstLocationLiteral(URI.create("tcp://localhost:8000")))
            .addAcceptedStream()
            .addConnectedEvent()
            .done()
            .addReadEvent()
            .addExactText("Hello, world")
            .done()
            .addWriteCommand()
            .addExactText("Hello, world")
            .done()
            .done()
            .done()
            .done();

    AstScriptNode inputScriptNode =
        new AstScriptNodeBuilder()
            .addAcceptStream()
            .setLocation(new AstLocationLiteral(URI.create("tcp://localhost:8000")))
            .done()
            .addAcceptedStream()
            .addConnectedEvent()
            .done()
            .addReadEvent()
            .addExactText("Hello, world")
            .done()
            .addWriteCommand()
            .addExactText("Hello, world")
            .done()
            .done()
            .done();

    AssociateStreamsVisitor injectBarriers = new AssociateStreamsVisitor();
    AstScriptNode actualScriptNode =
        inputScriptNode.accept(injectBarriers, new AssociateStreamsVisitor.State());

    assertEquals(expectedScriptNode, actualScriptNode);
  }
 @Override
 public R done() {
   AstScriptNode scriptNode = result.node;
   scriptNode.getStreams().add(node);
   return result;
 }