Search in sources :

Example 11 with AttributeMap

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);
}
Also used : AttributeMap(com.datatorrent.api.Attribute.AttributeMap) Attribute(com.datatorrent.api.Attribute) TestPortContext(org.apache.apex.malhar.lib.helper.TestPortContext) Before(org.junit.Before)

Example 12 with AttributeMap

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();
}
Also used : CouchbaseMock(org.couchbase.mock.CouchbaseMock) CouchbaseConnectionFactoryBuilder(com.couchbase.client.CouchbaseConnectionFactoryBuilder) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BucketConfiguration(org.couchbase.mock.BucketConfiguration) IOException(java.io.IOException) URI(java.net.URI) AttributeMap(com.datatorrent.api.Attribute.AttributeMap) OperatorContextTestHelper.mockOperatorContext(org.apache.apex.malhar.lib.helper.OperatorContextTestHelper.mockOperatorContext) OperatorContext(com.datatorrent.api.Context.OperatorContext) Test(org.junit.Test)

Aggregations

AttributeMap (com.datatorrent.api.Attribute.AttributeMap)12 OperatorContext (com.datatorrent.api.Context.OperatorContext)10 OperatorContextTestHelper.mockOperatorContext (org.apache.apex.malhar.lib.helper.OperatorContextTestHelper.mockOperatorContext)10 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)7 FilePartitionMapping (org.apache.apex.malhar.hive.AbstractFSRollingOutputOperator.FilePartitionMapping)4 CollectorTestSink (org.apache.apex.malhar.lib.testbench.CollectorTestSink)4 CouchbaseConnectionFactoryBuilder (com.couchbase.client.CouchbaseConnectionFactoryBuilder)2 Attribute (com.datatorrent.api.Attribute)2 IOException (java.io.IOException)2 URI (java.net.URI)2 HashMap (java.util.HashMap)2 TestPortContext (org.apache.apex.malhar.lib.helper.TestPortContext)2 BucketConfiguration (org.couchbase.mock.BucketConfiguration)2 CouchbaseMock (org.couchbase.mock.CouchbaseMock)2 CouchbaseClient (com.couchbase.client.CouchbaseClient)1 Partition (com.datatorrent.api.Partitioner.Partition)1 Kryo (com.esotericsoftware.kryo.Kryo)1 FieldSerializer (com.esotericsoftware.kryo.serializers.FieldSerializer)1 ResultSet (java.sql.ResultSet)1