[hotfix] [core] Demockitofy state descriptor tests

Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/13ef4e44
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/13ef4e44
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/13ef4e44

Branch: refs/heads/master
Commit: 13ef4e4406d749fbfe41f5d30d0849d0c70661d1
Parents: d766988
Author: Stephan Ewen <[email protected]>
Authored: Tue Mar 20 15:36:19 2018 +0100
Committer: Stephan Ewen <[email protected]>
Committed: Thu Mar 22 15:42:34 2018 +0100

----------------------------------------------------------------------
 .../state/AggregatingStateDescriptorTest.java   | 16 +++++---------
 .../common/state/ListStateDescriptorTest.java   | 14 +++---------
 .../common/state/MapStateDescriptorTest.java    | 23 ++++----------------
 .../state/ReducingStateDescriptorTest.java      | 22 +++++++------------
 .../common/state/ValueStateDescriptorTest.java  | 14 +++---------
 5 files changed, 23 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/13ef4e44/flink-core/src/test/java/org/apache/flink/api/common/state/AggregatingStateDescriptorTest.java
----------------------------------------------------------------------
diff --git 
a/flink-core/src/test/java/org/apache/flink/api/common/state/AggregatingStateDescriptorTest.java
 
b/flink-core/src/test/java/org/apache/flink/api/common/state/AggregatingStateDescriptorTest.java
index 155f23a..f62acc8 100644
--- 
a/flink-core/src/test/java/org/apache/flink/api/common/state/AggregatingStateDescriptorTest.java
+++ 
b/flink-core/src/test/java/org/apache/flink/api/common/state/AggregatingStateDescriptorTest.java
@@ -18,17 +18,16 @@
 
 package org.apache.flink.api.common.state;
 
+import org.apache.flink.api.common.ExecutionConfig;
 import org.apache.flink.api.common.functions.AggregateFunction;
 import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer;
 import org.apache.flink.util.TestLogger;
 
 import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
 
 import static org.junit.Assert.assertNotSame;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 /**
  * Tests for the {@link AggregatingStateDescriptor}.
@@ -41,16 +40,11 @@ public class AggregatingStateDescriptorTest extends 
TestLogger {
         * <p>Tests that the returned serializer is duplicated. This allows to
         * share the state descriptor.
         */
-       @SuppressWarnings("unchecked")
        @Test
        public void testSerializerDuplication() {
-               TypeSerializer<Long> serializer = mock(TypeSerializer.class);
-               when(serializer.duplicate()).thenAnswer(new 
Answer<TypeSerializer<Long>>() {
-                       @Override
-                       public TypeSerializer<Long> answer(InvocationOnMock 
invocation) throws Throwable {
-                               return mock(TypeSerializer.class);
-                       }
-               });
+               // we need a serializer that actually duplicates for testing (a 
stateful one)
+               // we use Kryo here, because it meets these conditions
+               TypeSerializer<Long> serializer = new 
KryoSerializer<>(Long.class, new ExecutionConfig());
 
                AggregateFunction<Long, Long, Long> aggregatingFunction = 
mock(AggregateFunction.class);
 

http://git-wip-us.apache.org/repos/asf/flink/blob/13ef4e44/flink-core/src/test/java/org/apache/flink/api/common/state/ListStateDescriptorTest.java
----------------------------------------------------------------------
diff --git 
a/flink-core/src/test/java/org/apache/flink/api/common/state/ListStateDescriptorTest.java
 
b/flink-core/src/test/java/org/apache/flink/api/common/state/ListStateDescriptorTest.java
index c6d086e..f45d296 100644
--- 
a/flink-core/src/test/java/org/apache/flink/api/common/state/ListStateDescriptorTest.java
+++ 
b/flink-core/src/test/java/org/apache/flink/api/common/state/ListStateDescriptorTest.java
@@ -28,8 +28,6 @@ import org.apache.flink.core.fs.Path;
 import org.apache.flink.core.testutils.CommonTestUtils;
 
 import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
 
 import java.util.List;
 
@@ -38,8 +36,6 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 /**
  * Tests for the {@link ListStateDescriptor}.
@@ -121,13 +117,9 @@ public class ListStateDescriptorTest {
        @SuppressWarnings("unchecked")
        @Test
        public void testSerializerDuplication() {
-               TypeSerializer<String> statefulSerializer = 
mock(TypeSerializer.class);
-               when(statefulSerializer.duplicate()).thenAnswer(new 
Answer<TypeSerializer<String>>() {
-                       @Override
-                       public TypeSerializer<String> answer(InvocationOnMock 
invocation) throws Throwable {
-                               return mock(TypeSerializer.class);
-                       }
-               });
+               // we need a serializer that actually duplicates for testing (a 
stateful one)
+               // we use Kryo here, because it meets these conditions
+               TypeSerializer<String> statefulSerializer = new 
KryoSerializer<>(String.class, new ExecutionConfig());
 
                ListStateDescriptor<String> descr = new 
ListStateDescriptor<>("foobar", statefulSerializer);
 

http://git-wip-us.apache.org/repos/asf/flink/blob/13ef4e44/flink-core/src/test/java/org/apache/flink/api/common/state/MapStateDescriptorTest.java
----------------------------------------------------------------------
diff --git 
a/flink-core/src/test/java/org/apache/flink/api/common/state/MapStateDescriptorTest.java
 
b/flink-core/src/test/java/org/apache/flink/api/common/state/MapStateDescriptorTest.java
index e2aa940..2151834 100644
--- 
a/flink-core/src/test/java/org/apache/flink/api/common/state/MapStateDescriptorTest.java
+++ 
b/flink-core/src/test/java/org/apache/flink/api/common/state/MapStateDescriptorTest.java
@@ -29,8 +29,6 @@ import org.apache.flink.core.fs.Path;
 import org.apache.flink.core.testutils.CommonTestUtils;
 
 import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
 
 import java.util.Map;
 
@@ -39,8 +37,6 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 /**
  * Tests for the {@link MapStateDescriptor}.
@@ -129,23 +125,12 @@ public class MapStateDescriptorTest {
         * <p>Tests that the returned serializer is duplicated. This allows to
         * share the state descriptor.
         */
-       @SuppressWarnings("unchecked")
        @Test
        public void testSerializerDuplication() {
-               TypeSerializer<String> keySerializer = 
mock(TypeSerializer.class);
-               TypeSerializer<Long> valueSerializer = 
mock(TypeSerializer.class);
-               when(keySerializer.duplicate()).thenAnswer(new 
Answer<TypeSerializer<String>>() {
-                       @Override
-                       public TypeSerializer<String> answer(InvocationOnMock 
invocation) throws Throwable {
-                               return mock(TypeSerializer.class);
-                       }
-               });
-               when(valueSerializer.duplicate()).thenAnswer(new 
Answer<TypeSerializer<Long>>() {
-                       @Override
-                       public TypeSerializer<Long> answer(InvocationOnMock 
invocation) throws Throwable {
-                               return mock(TypeSerializer.class);
-                       }
-               });
+               // we need a serializer that actually duplicates for testing (a 
stateful one)
+               // we use Kryo here, because it meets these conditions
+               TypeSerializer<String> keySerializer = new 
KryoSerializer<>(String.class, new ExecutionConfig());
+               TypeSerializer<Long> valueSerializer = new 
KryoSerializer<>(Long.class, new ExecutionConfig());
 
                MapStateDescriptor<String, Long> descr = new 
MapStateDescriptor<>("foobar", keySerializer, valueSerializer);
 

http://git-wip-us.apache.org/repos/asf/flink/blob/13ef4e44/flink-core/src/test/java/org/apache/flink/api/common/state/ReducingStateDescriptorTest.java
----------------------------------------------------------------------
diff --git 
a/flink-core/src/test/java/org/apache/flink/api/common/state/ReducingStateDescriptorTest.java
 
b/flink-core/src/test/java/org/apache/flink/api/common/state/ReducingStateDescriptorTest.java
index ef39f14..1e21a78 100644
--- 
a/flink-core/src/test/java/org/apache/flink/api/common/state/ReducingStateDescriptorTest.java
+++ 
b/flink-core/src/test/java/org/apache/flink/api/common/state/ReducingStateDescriptorTest.java
@@ -29,8 +29,6 @@ import org.apache.flink.core.testutils.CommonTestUtils;
 import org.apache.flink.util.TestLogger;
 
 import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -38,7 +36,6 @@ import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 /**
  * Tests for the {@link ReducingStateDescriptor}.
@@ -118,17 +115,14 @@ public class ReducingStateDescriptorTest extends 
TestLogger {
        @SuppressWarnings("unchecked")
        @Test
        public void testSerializerDuplication() {
-               TypeSerializer<String> statefulSerializer = 
mock(TypeSerializer.class);
-               when(statefulSerializer.duplicate()).thenAnswer(new 
Answer<TypeSerializer<String>>() {
-                       @Override
-                       public TypeSerializer<String> answer(InvocationOnMock 
invocation) throws Throwable {
-                               return mock(TypeSerializer.class);
-                       }
-               });
-
-               ReduceFunction<String> reducer = mock(ReduceFunction.class);
-
-               ReducingStateDescriptor<String> descr = new 
ReducingStateDescriptor<>("foobar", reducer, statefulSerializer);
+               // we need a serializer that actually duplicates for testing (a 
stateful one)
+               // we use Kryo here, because it meets these conditions
+               TypeSerializer<String> statefulSerializer = new 
KryoSerializer<>(String.class, new ExecutionConfig());
+
+               ReducingStateDescriptor<String> descr = new 
ReducingStateDescriptor<>(
+                               "foobar",
+                               (a, b) -> a,
+                               statefulSerializer);
 
                TypeSerializer<String> serializerA = descr.getSerializer();
                TypeSerializer<String> serializerB = descr.getSerializer();

http://git-wip-us.apache.org/repos/asf/flink/blob/13ef4e44/flink-core/src/test/java/org/apache/flink/api/common/state/ValueStateDescriptorTest.java
----------------------------------------------------------------------
diff --git 
a/flink-core/src/test/java/org/apache/flink/api/common/state/ValueStateDescriptorTest.java
 
b/flink-core/src/test/java/org/apache/flink/api/common/state/ValueStateDescriptorTest.java
index b43e5ad..f3b9eee 100644
--- 
a/flink-core/src/test/java/org/apache/flink/api/common/state/ValueStateDescriptorTest.java
+++ 
b/flink-core/src/test/java/org/apache/flink/api/common/state/ValueStateDescriptorTest.java
@@ -29,8 +29,6 @@ import org.apache.flink.core.testutils.CommonTestUtils;
 import org.apache.flink.util.TestLogger;
 
 import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
 
 import java.io.File;
 
@@ -39,8 +37,6 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 /**
  * Tests for the {@link ValueStateDescriptor}.
@@ -149,13 +145,9 @@ public class ValueStateDescriptorTest extends TestLogger {
        @SuppressWarnings("unchecked")
        @Test
        public void testSerializerDuplication() {
-               TypeSerializer<String> statefulSerializer = 
mock(TypeSerializer.class);
-               when(statefulSerializer.duplicate()).thenAnswer(new 
Answer<TypeSerializer<String>>() {
-                       @Override
-                       public TypeSerializer<String> answer(InvocationOnMock 
invocation) throws Throwable {
-                               return mock(TypeSerializer.class);
-                       }
-               });
+               // we need a serializer that actually duplicates for testing (a 
stateful one)
+               // we use Kryo here, because it meets these conditions
+               TypeSerializer<String> statefulSerializer = new 
KryoSerializer<>(String.class, new ExecutionConfig());
 
                ValueStateDescriptor<String> descr = new 
ValueStateDescriptor<>("foobar", statefulSerializer);
 

Reply via email to