| /** |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| package com.datatorrent.lib.algo; |
| |
| import java.util.HashMap; |
| |
| import org.junit.Assert; |
| import org.junit.Test; |
| |
| import com.datatorrent.lib.testbench.CountAndLastTupleTestSink; |
| |
| /** |
| * @deprecated |
| * Functional tests for {@link com.datatorrent.lib.algo.MatchAllMap}<p> |
| * (Deprecating inclass) Comment: MatchAllMap is deprecated. |
| */ |
| @Deprecated |
| public class MatchAllMapTest |
| { |
| /** |
| * Test node logic emits correct results |
| */ |
| @Test |
| public void testNodeProcessing() throws Exception |
| { |
| testNodeProcessingSchema(new MatchAllMap<String, Integer>()); |
| testNodeProcessingSchema(new MatchAllMap<String, Double>()); |
| testNodeProcessingSchema(new MatchAllMap<String, Float>()); |
| testNodeProcessingSchema(new MatchAllMap<String, Short>()); |
| testNodeProcessingSchema(new MatchAllMap<String, Long>()); |
| } |
| |
| @SuppressWarnings({ "rawtypes", "unchecked" }) |
| public void testNodeProcessingSchema(MatchAllMap oper) |
| { |
| CountAndLastTupleTestSink matchSink = new CountAndLastTupleTestSink(); |
| oper.all.setSink(matchSink); |
| oper.setKey("a"); |
| oper.setValue(3.0); |
| oper.setTypeEQ(); |
| |
| oper.beginWindow(0); |
| HashMap<String, Number> input = new HashMap<String, Number>(); |
| input.put("a", 3); |
| input.put("b", 20); |
| input.put("c", 1000); |
| oper.data.process(input); |
| input.clear(); |
| input.put("a", 3); |
| oper.data.process(input); |
| oper.endWindow(); |
| |
| Assert.assertEquals("number emitted tuples", 1, matchSink.count); |
| Boolean result = (Boolean)matchSink.tuple; |
| Assert.assertEquals("result was false", true, result); |
| matchSink.clear(); |
| |
| oper.beginWindow(0); |
| input.put("a", 2); |
| input.put("b", 20); |
| input.put("c", 1000); |
| oper.data.process(input); |
| input.clear(); |
| input.put("a", 3); |
| oper.data.process(input); |
| oper.endWindow(); |
| Assert.assertEquals("number emitted tuples", 1, matchSink.count); |
| result = (Boolean)matchSink.tuple; |
| Assert.assertEquals("result was false", false, result); |
| matchSink.clear(); |
| } |
| } |