org.apache.edgent.function.Functions.unpartitioned()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(5.5k)|赞(0)|评价(0)|浏览(129)

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

Functions.unpartitioned介绍

[英]Returns a constant function that returns zero (0). This is identical to #zero() but is more readable when applied as a key function.
[中]返回一个返回零(0)的常量函数。这与#zero()相同,但作为键函数应用时可读性更强。

代码示例

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

@Test
public void testUnpartitioned() {
  String s = "hello";
  assertEquals(Integer.valueOf(0), unpartitioned().apply(s));
  
  Integer i = 42;
  assertEquals(Integer.valueOf(0), unpartitioned().apply(i));
  
  Object o = new Object();
  assertEquals(Integer.valueOf(0), unpartitioned().apply(o));
}
@Test

代码示例来源:origin: org.apache.edgent/edgent-connectors-iot

Functions.unpartitioned(), 1).tag("pressureRelieved");

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

Functions.unpartitioned(), 1).tag("pressureRelieved");

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

final int COUNT = 100;
Window<Integer, Integer, ? extends List<Integer>> window = Windows.lastNProcessOnInsert(10, unpartitioned());

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

ses.scheduleAtFixedRate(() -> {partition.process();}, 0, 1000, TimeUnit.MILLISECONDS);
  }}, 
unpartitioned(),
() -> new InsertionTimeList<Long>());

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

}, 1, TimeUnit.MILLISECONDS);
TWindow<Long, Integer> window = times.last(1, TimeUnit.SECONDS, unpartitioned());
assertSame(zero(), window.getKeyFunction());
TStream<Long> diffStream = window.aggregate((tuples, key) -> {

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

@Test
public void testWindowSum() throws Exception {
  Topology t = newTopology();
  
  TStream<Integer> integers = t.collection(Arrays.asList(1,2,3,4));
  TWindow<Integer, Integer> window = integers.last(4, unpartitioned());
  assertSame(unpartitioned(), window.getKeyFunction());
  TStream<Integer> sums = window.aggregate((tuples, key) -> {
    assertEquals(Integer.valueOf(0), key);
    int sum = 0;
    for(Integer tuple : tuples)
      sum+=tuple;
    return sum;
  });
  Condition<Long> tc = t.getTester().tupleCount(sums, 4);
  Condition<List<Integer>> contents = t.getTester().streamContents(sums, 1, 3, 6, 10);
  complete(t, tc);
  assertTrue(contents.valid());
}

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

@Test
public void testAggregateNStream() throws Exception {
 // Aggregations.aggregate are ignorant of Stream/Window but
 // to be safe verify a full Stream/Window based use case works
 
 UnivariateAggregate[] stats = STAT_RESULTS.keySet().toArray(new UnivariateAggregate[0]);
 
 Topology topology = newTopology("testAggregateNStream");
 
 // (1, 4, 102, 0)
 TStream<Integer> sourceData = sourceData(topology);
 
 TWindow<Integer, Integer> window = sourceData.last(2, Functions.unpartitioned());
 
 TStream<ResultMap> aggregate = window.aggregate( (list,partition) -> {
   return Aggregations.aggregateN(list, stats);
 });
 
 Condition<Long> count = topology.getTester().atLeastTupleCount(aggregate, 4);
 Condition<List<ResultMap>> contents = topology.getTester().streamContents(aggregate);
 complete(topology, count);
 assertTrue(count.valid());
  
 List<ResultMap> tuples = contents.getResult();
 assertEquals(4, tuples.size());
 
 for (int i = 0; i < tuples.size(); i++) {
  assertResult(i, stats, STAT_RESULTS, tuples.get(i));
 }
}

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

TStream<TimeAndId> pr = PlumbingStreams.pressureReliever(raw, Functions.unpartitioned(), 1);

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

.map(i -> new SensorReadings(i, i+1000));
TWindow<SensorReadings, Integer> window = sourceData.last(2, Functions.unpartitioned());

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

@Test
public void testPressureRelieverNoDrop() throws Exception {
  Topology topology = newTopology();
  
  // Same pipeline config as testPressureRelieverDrop but the reliever queue is
  // big enough to avoid drops
  String[] tuples = {"A", "B", "C", "D", "E", "F", "G", "H"};
  TStream<String> raw = topology.strings(tuples);
  
  TStream<String> pr = PlumbingStreams.pressureReliever(raw, Functions.unpartitioned(), 100);
  
  TStream<String> pr2 = PlumbingStreams.blockingOneShotDelay(pr, 1, TimeUnit.SECONDS);
  
  Condition<Long> tcCount = topology.getTester().tupleCount(pr2, tuples.length);
  Condition<List<String>> contents = topology.getTester().streamContents(pr2, tuples);
  complete(topology, tcCount);
  
  assertTrue(tcCount.valid());
  assertTrue(contents.valid());
}

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

@Test
public void testPressureRelieverDrop() throws Exception {
  Topology topology = newTopology();
  
  // Verify the pressureReliever drops and retains the most recent when
  // backpressure exists.
  //
  // Here, all the tuples hit the reliever at once, the downstream processing (oneShotDelay)
  // causes a backup causing the reliever's queue to become full and drop tuples.
  // The first tuple should be processed, then the last (most recent) N (N==queue depth).
  
  String[] tuples = {"A", "B", "C", "D", "E", "F", "G", "H"};
  String[] expTuples = {"A", "F", "G", "H"};  // with queue depth of 3
  TStream<String> raw = topology.strings(tuples);
  
  TStream<String> pr = PlumbingStreams.pressureReliever(raw, Functions.unpartitioned(), 3);
  
  TStream<String> pr2 = PlumbingStreams.blockingOneShotDelay(pr, 1, TimeUnit.SECONDS);
  
  Condition<Long> tcCount = topology.getTester().tupleCount(pr2, expTuples.length);
  Condition<List<String>> contents = topology.getTester().streamContents(pr2, expTuples);
  complete(topology, tcCount);
  
  assertTrue(tcCount.valid());
  assertTrue(contents.valid());
}

相关文章