use of org.apache.apex.malhar.lib.util.KeyValPair in project apex-malhar by apache.
the class CalculatorOperatorTest method testStandarDeviation.
public void testStandarDeviation(CalculatorOperator oper) {
CollectorTestSink sortSink = new CollectorTestSink();
oper.sdOutputPort.setSink(sortSink);
Calendar calendar = Calendar.getInstance();
Date date = calendar.getTime();
String timeKey = minuteDateFormat.format(date);
String day = calendar.get(Calendar.DAY_OF_MONTH) + "";
Integer vs = new Integer(1);
MachineKey mk = new MachineKey(timeKey, day, vs, vs, vs, vs, vs, vs, vs);
oper.beginWindow(0);
MachineInfo info = new MachineInfo(mk, 1, 1, 1);
oper.dataPort.process(info);
info.setCpu(2);
oper.dataPort.process(info);
info.setCpu(3);
oper.dataPort.process(info);
oper.endWindow();
Assert.assertEquals("number emitted tuples", 1, sortSink.collectedTuples.size());
for (Object o : sortSink.collectedTuples) {
LOG.debug(o.toString());
KeyValPair<TimeBucketKey, Map<ResourceType, Double>> keyValPair = (KeyValPair<TimeBucketKey, Map<ResourceType, Double>>) o;
Assert.assertEquals("emitted value for 'cpu' was ", getSD(ImmutableList.of(1, 2, 3)), keyValPair.getValue().get(ResourceType.CPU), 0);
Assert.assertEquals("emitted value for 'hdd' was ", getSD(ImmutableList.of(1, 1, 1)), keyValPair.getValue().get(ResourceType.HDD), 0);
Assert.assertEquals("emitted value for 'ram' was ", getSD(ImmutableList.of(1, 1, 1)), keyValPair.getValue().get(ResourceType.RAM), 0);
}
LOG.debug("Done sd testing\n");
}
use of org.apache.apex.malhar.lib.util.KeyValPair in project apex-malhar by apache.
the class CalculatorOperatorTest method testPercentile.
public void testPercentile(CalculatorOperator oper) {
CollectorTestSink sortSink = new CollectorTestSink();
oper.percentileOutputPort.setSink(sortSink);
oper.setKthPercentile(50);
Calendar calendar = Calendar.getInstance();
Date date = calendar.getTime();
String timeKey = minuteDateFormat.format(date);
String day = calendar.get(Calendar.DAY_OF_MONTH) + "";
Integer vs = new Integer(1);
MachineKey mk = new MachineKey(timeKey, day, vs, vs, vs, vs, vs, vs, vs);
oper.beginWindow(0);
MachineInfo info = new MachineInfo(mk, 1, 1, 1);
oper.dataPort.process(info);
info.setCpu(2);
oper.dataPort.process(info);
info.setCpu(3);
oper.dataPort.process(info);
oper.endWindow();
Assert.assertEquals("number emitted tuples", 1, sortSink.collectedTuples.size());
for (Object o : sortSink.collectedTuples) {
LOG.debug(o.toString());
KeyValPair<TimeBucketKey, Map<ResourceType, Double>> keyValPair = (KeyValPair<TimeBucketKey, Map<ResourceType, Double>>) o;
Assert.assertEquals("emitted value for 'cpu' was ", 2.0, keyValPair.getValue().get(ResourceType.CPU), 0);
Assert.assertEquals("emitted value for 'hdd' was ", 1.0, keyValPair.getValue().get(ResourceType.HDD), 0);
Assert.assertEquals("emitted value for 'ram' was ", 1.0, keyValPair.getValue().get(ResourceType.RAM), 0);
}
LOG.debug("Done percentile testing\n");
}
use of org.apache.apex.malhar.lib.util.KeyValPair in project apex-malhar by apache.
the class PojoOuterJoinTest method PojoLeftOuterJoinTestWithMap.
@Test
public void PojoLeftOuterJoinTestWithMap() {
String[] leftKeys = { "uId", "uName" };
String[] rightKeys = { "uId", "uNickName" };
Map<String, KeyValPair<AbstractPojoJoin.STREAM, String>> outputInputMap = new HashMap<>();
outputInputMap.put("uId", new KeyValPair<>(AbstractPojoJoin.STREAM.LEFT, "uId"));
outputInputMap.put("age", new KeyValPair<>(AbstractPojoJoin.STREAM.RIGHT, "age"));
PojoLeftOuterJoin<TestPojo1, TestPojo3> pij = new PojoLeftOuterJoin<>(TestOutClass.class, leftKeys, rightKeys, outputInputMap);
List<Multimap<List<Object>, Object>> accu = pij.defaultAccumulatedValue();
Assert.assertEquals(2, accu.size());
accu = pij.accumulate(accu, new TestPojo1(1, "Josh"));
accu = pij.accumulate(accu, new TestPojo1(2, "Bob"));
accu = pij.accumulate2(accu, new TestPojo3(1, "Josh", 12));
accu = pij.accumulate2(accu, new TestPojo3(3, "ECE", 13));
List result = pij.getOutput(accu);
Assert.assertEquals(2, result.size());
Object o = result.get(0);
Assert.assertTrue(o instanceof TestOutClass);
TestOutClass testOutClass = (TestOutClass) o;
int uId = testOutClass.getUId();
if (uId == 1) {
checkNameAge(null, 12, testOutClass);
o = result.get(1);
Assert.assertTrue(o instanceof TestOutClass);
testOutClass = (TestOutClass) o;
uId = testOutClass.getUId();
Assert.assertEquals(2, uId);
checkNameAge(null, 0, testOutClass);
} else if (uId == 2) {
checkNameAge(null, 0, testOutClass);
o = result.get(1);
Assert.assertTrue(o instanceof TestOutClass);
testOutClass = (TestOutClass) o;
uId = testOutClass.getUId();
Assert.assertEquals(1, uId);
checkNameAge(null, 12, testOutClass);
}
}
use of org.apache.apex.malhar.lib.util.KeyValPair in project apex-malhar by apache.
the class PojoOuterJoinTest method PojoRightOuterJoinTestWithMap.
@Test
public void PojoRightOuterJoinTestWithMap() {
String[] leftKeys = { "uId", "uName" };
String[] rightKeys = { "uId", "uNickName" };
Map<String, KeyValPair<AbstractPojoJoin.STREAM, String>> outputInputMap = new HashMap<>();
outputInputMap.put("uId", new KeyValPair<>(AbstractPojoJoin.STREAM.LEFT, "uId"));
outputInputMap.put("age", new KeyValPair<>(AbstractPojoJoin.STREAM.RIGHT, "age"));
PojoRightOuterJoin<TestPojo1, TestPojo3> pij = new PojoRightOuterJoin<>(TestOutClass.class, leftKeys, rightKeys, outputInputMap);
List<Multimap<List<Object>, Object>> accu = pij.defaultAccumulatedValue();
Assert.assertEquals(2, accu.size());
accu = pij.accumulate(accu, new TestPojo1(1, "Josh"));
accu = pij.accumulate(accu, new TestPojo1(2, "Bob"));
accu = pij.accumulate2(accu, new TestPojo3(1, "Josh", 12));
accu = pij.accumulate2(accu, new TestPojo3(3, "Bob", 13));
List result = pij.getOutput(accu);
Assert.assertEquals(2, result.size());
Object o = result.get(0);
Assert.assertTrue(o instanceof TestOutClass);
TestOutClass testOutClass = (TestOutClass) o;
int uId = testOutClass.getUId();
if (uId == 1) {
checkNameAge(null, 12, testOutClass);
o = result.get(1);
Assert.assertTrue(o instanceof TestOutClass);
testOutClass = (TestOutClass) o;
uId = testOutClass.getUId();
Assert.assertEquals(0, uId);
checkNameAge(null, 13, testOutClass);
} else if (uId == 0) {
checkNameAge(null, 13, testOutClass);
o = result.get(1);
Assert.assertTrue(o instanceof TestOutClass);
testOutClass = (TestOutClass) o;
uId = testOutClass.getUId();
Assert.assertEquals(1, uId);
checkNameAge(null, 12, testOutClass);
}
}
use of org.apache.apex.malhar.lib.util.KeyValPair in project apex-malhar by apache.
the class WindowedMergeOperatorTest method keyedWindowedMergeOperatorMergeTest.
@Test
public void keyedWindowedMergeOperatorMergeTest() {
KeyedWindowedMergeOperatorImpl<String, Integer, Integer, List<Set<Integer>>, List<List<Integer>>> op = createDefaultKeyedWindowedMergeOperator();
Window global = Window.GlobalWindow.INSTANCE;
op.setDataStorage(new InMemoryWindowedKeyedStorage<String, List<Set<Integer>>>());
op.setWindowOption(new WindowOption.GlobalWindow());
op.initializeWindowStates(AbstractWindowedOperator.GLOBAL_WINDOW_SINGLETON_SET);
op.processTuple(new Tuple.WindowedTuple<KeyValPair<String, Integer>>(global, new KeyValPair<String, Integer>("A", 100)));
Assert.assertEquals(1, op.dataStorage.get(global, "A").get(0).size());
Assert.assertTrue(op.dataStorage.get(global, "A").get(0).contains(100));
op.processTuple2(new Tuple.WindowedTuple<KeyValPair<String, Integer>>(global, new KeyValPair<String, Integer>("A", 200)));
Assert.assertEquals(1, op.dataStorage.get(global, "A").get(1).size());
Assert.assertTrue(op.dataStorage.get(global, "A").get(1).contains(200));
op.processTuple2(new Tuple.WindowedTuple<KeyValPair<String, Integer>>(global, new KeyValPair<String, Integer>("B", 300)));
Assert.assertEquals(1, op.dataStorage.get(global, "A").get(1).size());
Assert.assertEquals(1, op.dataStorage.get(global, "B").get(1).size());
Assert.assertTrue(op.dataStorage.get(global, "B").get(1).contains(300));
Assert.assertEquals(2, op.accumulation.getOutput(op.dataStorage.get(global, "A")).size());
}
Aggregations