org.apache.edgent.topology.Topology.generate()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(2.2k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中org.apache.edgent.topology.Topology.generate()方法的一些代码示例,展示了Topology.generate()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Topology.generate()方法的具体详情如下:
包路径:org.apache.edgent.topology.Topology
类名称:Topology
方法名:generate

Topology.generate介绍

[英]Declare an endless source stream. data.get() will be called repeatably. Each non-null returned value will be present on the stream.

If data implements AutoCloseable, its close()method will be called when the topology's execution is terminated.
[中]宣布源源不断。数据get()将被重复调用。每个非空返回值都将出现在流中。
如果数据实现了AutoCloseable,则在拓扑执行终止时将调用其close()方法。

代码示例

代码示例来源:origin: apache/incubator-edgent

return topology.generate(endlessCommandReader(cmd));

代码示例来源:origin: apache/incubator-edgent

@Test
public void jobProcessSource() throws Exception {
  Topology t = newTopology();
  AtomicInteger n = new AtomicInteger(0);
  @SuppressWarnings("unused")
  TStream<Integer> ints = t.generate(() -> n.incrementAndGet());
  Future<Job> fj = ((DirectProvider)getTopologyProvider()).submit(t);
  Job job = fj.get();
  assertEquals(Job.State.RUNNING, job.getCurrentState());
  assertEquals(Job.Health.HEALTHY, job.getHealth());
  assertEquals("", job.getLastError());
  Thread.sleep(TimeUnit.SECONDS.toMillis(2));
  assertTrue(n.get() > 0); // At least one tuple was processed
  job.stateChange(Job.Action.CLOSE);
  assertEquals(Job.State.CLOSED, job.getCurrentState());
  assertEquals(Job.Health.HEALTHY, job.getHealth());
  assertEquals("", job.getLastError());
}

代码示例来源:origin: apache/incubator-edgent

@Test(expected = ExecutionException.class)
public void jobProcessSourceError() throws Exception {
  Topology t = newTopology();
  AtomicInteger n = new AtomicInteger(0);
  TStream<Integer> ints = t.generate(() -> n.incrementAndGet());
  ints.pipe(new FailedOplet<Integer>(12, 100));
  Future<Job> fj = ((DirectProvider)getTopologyProvider()).submit(t);
  Job job = fj.get();
  assertEquals(Job.State.RUNNING, job.getCurrentState());
  try {
    job.complete(10, TimeUnit.SECONDS); 
  } finally {
    // RUNNING even though execution error 
    assertEquals(Job.State.RUNNING, job.getCurrentState());
    assertEquals(Job.Health.UNHEALTHY, job.getHealth());
    assertEquals("java.lang.RuntimeException: Expected Test Exception", job.getLastError());
  }
}

相关文章