Search in sources :

Example 11 with TupleSink

use of edu.uci.ics.texera.dataflow.sink.tuple.TupleSink in project textdb by TextDB.

the class TupleSinkTest method testGetNextTuple.

@Test
public void testGetNextTuple() throws Exception {
    TupleSink tupleSink = new TupleSink();
    tupleSink.setInputOperator(inputOperator);
    tupleSink.open();
    Tuple tuple = tupleSink.getNextTuple();
    Assert.assertEquals("test1", tuple.getField("content").getValue());
    tupleSink.close();
}
Also used : TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 12 with TupleSink

use of edu.uci.ics.texera.dataflow.sink.tuple.TupleSink in project textdb by TextDB.

the class TupleSinkTest method testOpenClose.

@Test
public void testOpenClose() throws Exception {
    TupleSink tupleSink = new TupleSink();
    tupleSink.setInputOperator(inputOperator);
    tupleSink.open();
    // verify that inputOperator called open() method
    // assert that the tuple stream sink removes the PAYLOAD attribute
    Assert.assertEquals(new Schema(SchemaConstants._ID_ATTRIBUTE, new Attribute("content", AttributeType.TEXT)), tupleSink.getOutputSchema());
    tupleSink.close();
}
Also used : TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) Test(org.junit.Test)

Example 13 with TupleSink

use of edu.uci.ics.texera.dataflow.sink.tuple.TupleSink in project textdb by TextDB.

the class TupleSinkTest method testLimitOffset.

/*
     * Test tuple sink predicate with limit 1 and offset 1.
     */
@Test
public void testLimitOffset() throws Exception {
    TupleSink tupleSink = new TupleSink(new TupleSinkPredicate(1, 1));
    tupleSink.setInputOperator(inputOperator);
    tupleSink.open();
    Tuple resultTuple1 = tupleSink.getNextTuple();
    Tuple resultTuple2 = tupleSink.getNextTuple();
    tupleSink.close();
    Assert.assertEquals("test2", resultTuple1.getField("content").getValue());
    Assert.assertTrue(resultTuple2 == null);
}
Also used : TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 14 with TupleSink

use of edu.uci.ics.texera.dataflow.sink.tuple.TupleSink in project textdb by TextDB.

the class TwitterFeedOperatorTest method testWithMockClient.

/**
 * Mock the TwitterConnector class and the BasicClient class inside it to test the TwitterFeedOperator alone.
 * Use the pre-defined queue with a Json formatted tweet to generate a tuple.
 * Check if the tuple is well-formatted.
 */
@Test
public void testWithMockClient() throws Exception {
    TwitterConnector mockTwitterConnector = mock(TwitterConnector.class);
    queue.add(inputStream);
    TwitterFeedSourcePredicate predicate = new TwitterFeedSourcePredicate(1, keywordList, "", null, null, null, null, null);
    TwitterFeedOperator operator = new TwitterFeedOperator(predicate, mockTwitterConnector);
    operator.setTimeout(timeOut);
    BasicClient mockClient = mock(BasicClient.class);
    when(mockTwitterConnector.getClient()).thenReturn(mockClient);
    when(mockTwitterConnector.getMsgQueue()).thenReturn(queue);
    TupleSink tupleSink = new TupleSink();
    tupleSink.setInputOperator(operator);
    tupleSink.open();
    List<Tuple> exactResults = tupleSink.collectAllTuples();
    tupleSink.close();
    JsonNode tweet = new ObjectMapper().readValue(inputStream, JsonNode.class);
    Tuple expectedTuple = new Tuple(TwitterUtils.TwitterSchema.TWITTER_SCHEMA, new TextField(TwitterUtils.getText(tweet)), new StringField(TwitterUtils.getMediaLink(tweet)), new StringField(TwitterUtils.getTweetLink(tweet)), new StringField(TwitterUtils.getUserLink(tweet)), new TextField(TwitterUtils.getUserScreenName(tweet)), new TextField(TwitterUtils.getUserName(tweet)), new TextField(TwitterUtils.getUserDescription(tweet)), new IntegerField(TwitterUtils.getUserFollowerCnt(tweet)), new IntegerField(TwitterUtils.getUserFriendsCnt(tweet)), new TextField(TwitterUtils.getUserLocation(tweet)), new StringField(TwitterUtils.getCreateTime(tweet)), new TextField(TwitterUtils.getPlaceName(tweet)), new StringField(TwitterUtils.getCoordinates(tweet)), new StringField(TwitterUtils.getLanguage(tweet)));
    String exactID = exactResults.get(0).getFields().get(0).getValue().toString();
    String expectedID = exactResults.get(0).getField(SchemaConstants._ID).getValue().toString();
    Assert.assertEquals(exactResults.size(), 1);
    Assert.assertEquals(exactID, expectedID);
    Assert.assertTrue(TwitterFeedTestHelper.compareTuple(exactResults, expectedTuple));
}
Also used : TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) JsonNode(com.fasterxml.jackson.databind.JsonNode) IntegerField(edu.uci.ics.texera.api.field.IntegerField) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) BasicClient(com.twitter.hbc.httpclient.BasicClient) Tuple(edu.uci.ics.texera.api.tuple.Tuple) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 15 with TupleSink

use of edu.uci.ics.texera.dataflow.sink.tuple.TupleSink in project textdb by TextDB.

the class EmojiSentimentTest method test1.

@Test
public void test1() throws TexeraException {
    TupleSourceOperator tupleSource = new TupleSourceOperator(Arrays.asList(EmojiSentimentTestConstants.POSITIVE_TUPLE1), EmojiSentimentTestConstants.SENTIMENT_SCHEMA);
    EmojiSentimentOperator sentiment = new EmojiSentimentOperator(new EmojiSentimentPredicate(EmojiSentimentTestConstants.TEXT, "sentiment"));
    TupleSink tupleSink = new TupleSink();
    sentiment.setInputOperator(tupleSource);
    tupleSink.setInputOperator(sentiment);
    tupleSink.open();
    List<Tuple> results = tupleSink.collectAllTuples();
    tupleSink.close();
    Tuple tuple = results.get(0);
    Assert.assertEquals(tuple.getField("sentiment").getValue(), SentimentConstants.POSITIVE);
}
Also used : TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) TupleSourceOperator(edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Aggregations

TupleSink (edu.uci.ics.texera.dataflow.sink.tuple.TupleSink)25 Test (org.junit.Test)23 Tuple (edu.uci.ics.texera.api.tuple.Tuple)17 TupleSourceOperator (edu.uci.ics.texera.dataflow.source.tuple.TupleSourceOperator)13 ISink (edu.uci.ics.texera.api.dataflow.ISink)8 Plan (edu.uci.ics.texera.api.engine.Plan)8 IOperator (edu.uci.ics.texera.api.dataflow.IOperator)7 RegexMatcher (edu.uci.ics.texera.dataflow.regexmatcher.RegexMatcher)7 Schema (edu.uci.ics.texera.api.schema.Schema)5 OneToNBroadcastConnector (edu.uci.ics.texera.dataflow.connector.OneToNBroadcastConnector)3 ConnectorOutputOperator (edu.uci.ics.texera.dataflow.connector.OneToNBroadcastConnector.ConnectorOutputOperator)3 Join (edu.uci.ics.texera.dataflow.join.Join)3 KeywordMatcherSourceOperator (edu.uci.ics.texera.dataflow.keywordmatcher.KeywordMatcherSourceOperator)3 NlpEntityOperator (edu.uci.ics.texera.dataflow.nlp.entity.NlpEntityOperator)3 HashSet (java.util.HashSet)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 BasicClient (com.twitter.hbc.httpclient.BasicClient)1