This is an automated email from the ASF dual-hosted git repository. tzulitai pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/flink-statefun.git
commit 822c6e6bba716f658eec3ccd8612997aa3fd6108 Author: Tzu-Li (Gordon) Tai <tzuli...@apache.org> AuthorDate: Mon Aug 31 16:58:23 2020 +0800 [hotfix] [core] Rename PersistedStates.findReflectivelyAndBind The renaming provides a better description that the method reflectively searches for fields marked with the @Persisted annotation and binds it to Flink state via a state binder. --- .../core/functions/StatefulFunctionRepository.java | 2 +- .../statefun/flink/core/state/PersistedStates.java | 3 ++- .../statefun/flink/core/state/PersistedStatesTest.java | 18 +++++++++--------- .../operator/StateBootstrapFunctionRegistry.java | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/functions/StatefulFunctionRepository.java b/statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/functions/StatefulFunctionRepository.java index af512d0..7c1af51 100644 --- a/statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/functions/StatefulFunctionRepository.java +++ b/statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/functions/StatefulFunctionRepository.java @@ -64,7 +64,7 @@ final class StatefulFunctionRepository implements FunctionRepository { functionLoader.load(functionType); try (SetContextClassLoader ignored = new SetContextClassLoader(statefulFunction)) { FlinkStateBinder stateBinderForType = new FlinkStateBinder(flinkState, functionType); - PersistedStates.findAndBind(statefulFunction, stateBinderForType); + PersistedStates.findReflectivelyAndBind(statefulFunction, stateBinderForType); FunctionTypeMetrics metrics = metricsFactory.forType(functionType); return new StatefulFunction(statefulFunction, metrics, messageFactory); } diff --git a/statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/state/PersistedStates.java b/statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/state/PersistedStates.java index 968e4b5..3e52adf 100644 --- a/statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/state/PersistedStates.java +++ b/statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/state/PersistedStates.java @@ -35,7 +35,8 @@ import org.apache.flink.statefun.sdk.state.PersistedValue; public final class PersistedStates { - public static void findAndBind(@Nullable Object instance, FlinkStateBinder stateBinder) { + public static void findReflectivelyAndBind( + @Nullable Object instance, FlinkStateBinder stateBinder) { List<?> states = findReflectively(instance); for (Object persisted : states) { if (persisted instanceof PersistedStateRegistry) { diff --git a/statefun-flink/statefun-flink-core/src/test/java/org/apache/flink/statefun/flink/core/state/PersistedStatesTest.java b/statefun-flink/statefun-flink-core/src/test/java/org/apache/flink/statefun/flink/core/state/PersistedStatesTest.java index adddcf5..ad07d5a 100644 --- a/statefun-flink/statefun-flink-core/src/test/java/org/apache/flink/statefun/flink/core/state/PersistedStatesTest.java +++ b/statefun-flink/statefun-flink-core/src/test/java/org/apache/flink/statefun/flink/core/state/PersistedStatesTest.java @@ -52,45 +52,45 @@ public class PersistedStatesTest { @Test public void exampleUsage() { - PersistedStates.findAndBind(new SanityClass(), binderUnderTest); + PersistedStates.findReflectivelyAndBind(new SanityClass(), binderUnderTest); assertThat(state.boundNames, hasItems("name", "last")); } @Test(expected = IllegalStateException.class) public void nullValueField() { - PersistedStates.findAndBind(new NullValueClass(), binderUnderTest); + PersistedStates.findReflectivelyAndBind(new NullValueClass(), binderUnderTest); } @Test public void nonAnnotatedClass() { - PersistedStates.findAndBind(new IgnoreNonAnnotated(), binderUnderTest); + PersistedStates.findReflectivelyAndBind(new IgnoreNonAnnotated(), binderUnderTest); assertTrue(state.boundNames.isEmpty()); } @Test public void extendedClass() { - PersistedStates.findAndBind(new ChildClass(), binderUnderTest); + PersistedStates.findReflectivelyAndBind(new ChildClass(), binderUnderTest); assertThat(state.boundNames, hasItems("parent", "child")); } @Test(expected = IllegalArgumentException.class) public void staticPersistedFieldsAreNotAllowed() { - PersistedStates.findAndBind(new StaticPersistedValue(), binderUnderTest); + PersistedStates.findReflectivelyAndBind(new StaticPersistedValue(), binderUnderTest); } @Test public void bindPersistedTable() { - PersistedStates.findAndBind(new PersistedTableValue(), binderUnderTest); + PersistedStates.findReflectivelyAndBind(new PersistedTableValue(), binderUnderTest); assertThat(state.boundNames, hasItems("table")); } @Test public void bindPersistedAppendingBuffer() { - PersistedStates.findAndBind(new PersistedAppendingBufferState(), binderUnderTest); + PersistedStates.findReflectivelyAndBind(new PersistedAppendingBufferState(), binderUnderTest); assertThat(state.boundNames, hasItems("buffer")); } @@ -98,7 +98,7 @@ public class PersistedStatesTest { @Test public void bindDynamicState() { DynamicState dynamicState = new DynamicState(); - PersistedStates.findAndBind(dynamicState, binderUnderTest); + PersistedStates.findReflectivelyAndBind(dynamicState, binderUnderTest); dynamicState.process(); @@ -115,7 +115,7 @@ public class PersistedStatesTest { @Test public void bindComposedState() { - PersistedStates.findAndBind(new OuterClass(), binderUnderTest); + PersistedStates.findReflectivelyAndBind(new OuterClass(), binderUnderTest); assertThat(state.boundNames, hasItems("inner")); } diff --git a/statefun-flink/statefun-flink-state-processor/src/main/java/org/apache/flink/statefun/flink/state/processor/operator/StateBootstrapFunctionRegistry.java b/statefun-flink/statefun-flink-state-processor/src/main/java/org/apache/flink/statefun/flink/state/processor/operator/StateBootstrapFunctionRegistry.java index 2825f75..f99b88d 100644 --- a/statefun-flink/statefun-flink-state-processor/src/main/java/org/apache/flink/statefun/flink/state/processor/operator/StateBootstrapFunctionRegistry.java +++ b/statefun-flink/statefun-flink-state-processor/src/main/java/org/apache/flink/statefun/flink/state/processor/operator/StateBootstrapFunctionRegistry.java @@ -117,7 +117,7 @@ public final class StateBootstrapFunctionRegistry implements Serializable { private static StateBootstrapFunction bindState( StateBootstrapFunction bootstrapFunction, FlinkStateBinder stateBinder) { try (SetContextClassLoader ignored = new SetContextClassLoader(bootstrapFunction)) { - PersistedStates.findAndBind(bootstrapFunction, stateBinder); + PersistedStates.findReflectivelyAndBind(bootstrapFunction, stateBinder); return bootstrapFunction; } }