use of com.datatorrent.api.Attribute.AttributeMap in project apex-malhar by apache.
the class CassandraOperatorTest method setupForTest.
@Before
public void setupForTest() {
AttributeMap.DefaultAttributeMap attributeMap = new AttributeMap.DefaultAttributeMap();
attributeMap.put(DAG.APPLICATION_ID, APP_ID);
context = mockOperatorContext(OPERATOR_ID, attributeMap);
Attribute.AttributeMap.DefaultAttributeMap portAttributes = new Attribute.AttributeMap.DefaultAttributeMap();
portAttributes.put(Context.PortContext.TUPLE_CLASS, TestPojo.class);
tpc = new TestPortContext(portAttributes);
}
use of com.datatorrent.api.Attribute.AttributeMap in project apex-malhar by apache.
the class CouchBaseOutputOperatorTest method TestCouchBaseOutputOperator.
@Test
public void TestCouchBaseOutputOperator() throws InterruptedException, Exception {
BucketConfiguration bucketConfiguration = new BucketConfiguration();
CouchbaseConnectionFactoryBuilder cfb = new CouchbaseConnectionFactoryBuilder();
CouchbaseMock mockCouchbase1 = createMock("default", "", bucketConfiguration);
mockCouchbase1.start();
mockCouchbase1.waitForStartup();
List<URI> uriList = new ArrayList<URI>();
int port1 = mockCouchbase1.getHttpPort();
logger.debug("port is {}", port1);
uriList.add(new URI("http", null, "localhost", port1, "/pools", "", ""));
cfb.buildCouchbaseConnection(uriList, bucketConfiguration.name, bucketConfiguration.password);
CouchBaseWindowStore store = new CouchBaseWindowStore();
store.setBucket(bucketConfiguration.name);
store.setPasswordConfig(password);
store.setPassword(bucketConfiguration.password);
store.setUriString("localhost:" + port1 + "," + "localhost:" + port1);
try {
store.connect();
} catch (IOException ex) {
DTThrowable.rethrow(ex);
}
store.getInstance().flush();
store.getMetaInstance().flush();
CouchbasePOJOSetOperator outputOperator = new CouchbasePOJOSetOperator();
AttributeMap.DefaultAttributeMap attributeMap = new AttributeMap.DefaultAttributeMap();
attributeMap.put(DAG.APPLICATION_ID, APP_ID);
OperatorContext context = mockOperatorContext(OPERATOR_ID, attributeMap);
outputOperator.setStore(store);
outputOperator.setup(context);
ArrayList<String> expressions = new ArrayList<String>();
expressions.add("getKey()");
expressions.add("getTest()");
outputOperator.setExpressions(expressions);
CouchBaseJSONSerializer serializer = new CouchBaseJSONSerializer();
outputOperator.setSerializer(serializer);
TestPojo obj = new TestPojo();
obj.setName("test");
obj.setPhone(123344555);
HashMap<String, Integer> map = new HashMap<String, Integer>();
map.put("test", 12345);
obj.setMap(map);
TestEvent1 testEvent = new TestEvent1();
testEvent.setKey("key1");
testEvent.setTest(obj);
outputOperator.beginWindow(0);
outputOperator.input.process(testEvent);
outputOperator.endWindow();
Assert.assertEquals("Value in couchbase is", "{\"name\":\"test\",\"map\":{\"test\":12345},\"phone\":123344555}", store.getInstance().get("key1").toString());
outputOperator.teardown();
outputOperator = new CouchbasePOJOSetOperator();
store = new CouchBaseWindowStore();
store.setBucket(bucketConfiguration.name);
store.setPasswordConfig(password);
store.setPassword(bucketConfiguration.password);
store.setUriString("localhost:" + port1 + "," + "localhost:" + port1);
try {
store.connect();
} catch (IOException ex) {
DTThrowable.rethrow(ex);
}
store.getInstance().flush();
store.getMetaInstance().flush();
outputOperator.setStore(store);
outputOperator.setup(context);
expressions = new ArrayList<String>();
expressions.add("getKey()");
expressions.add("getNum()");
outputOperator.setExpressions(expressions);
TestEvent2 simpleEvent = new TestEvent2("key2", 123);
outputOperator.beginWindow(0);
outputOperator.input.process(simpleEvent);
outputOperator.endWindow();
Assert.assertEquals("Value in couchbase is", "123", store.getInstance().get("key2").toString());
outputOperator.teardown();
mockCouchbase1.stop();
}
Aggregations