@@ -0,0 +1,3167 @@
+/*%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements. See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License. You may obtain a copy of the License at%0A *%0A *    http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.apache.kafka.streams.kstream.internals;%0A%0Aimport org.apache.kafka.streams.processor.Processor;%0Aimport org.apache.kafka.streams.processor.internals.AbstractProcessorContext;%0Aimport org.apache.kafka.streams.processor.internals.ProcessorNode;%0Aimport org.apache.kafka.streams.state.internals.InMemoryKeyValueStore;%0Aimport org.apache.kafka.test.InternalMockProcessorContext;%0Aimport org.junit.Test;%0A%0Aimport java.util.HashSet;%0Aimport java.util.Set;%0A%0Aimport static java.util.Collections.emptySet;%0Aimport static java.util.Collections.singleton;%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertNotNull;%0A%0Apublic class KTableReduceTest %7B%0A%0A    @Test%0A    public void shouldAddAndSubtract() %7B%0A        final AbstractProcessorContext context = new InternalMockProcessorContext();%0A%0A        final Processor%3CString, Change%3CSet%3CString%3E%3E%3E reduceProcessor =%0A            new KTableReduce%3CString, Set%3CString%3E%3E(%0A                %22myStore%22,%0A                this::unionNotNullArgs,%0A                this::differenceNotNullArgs%0A            ).get();%0A%0A%0A        final InMemoryKeyValueStore%3CString, Set%3CString%3E%3E myStore =%0A            new InMemoryKeyValueStore%3C%3E(%22myStore%22, null, null);%0A%0A        context.register(myStore, null);%0A        reduceProcessor.init(context);%0A        context.setCurrentNode(new ProcessorNode%3C%3E(%22reduce%22, reduceProcessor, singleton(%22myStore%22)));%0A%0A        reduceProcessor.process(%22A%22, new Change%3C%3E(singleton(%22a%22), null));%0A        assertEquals(singleton(%22a%22), myStore.get(%22A%22));%0A        reduceProcessor.process(%22A%22, new Change%3C%3E(singleton(%22b%22), singleton(%22a%22)));%0A        assertEquals(singleton(%22b%22), myStore.get(%22A%22));%0A        reduceProcessor.process(%22A%22, new Change%3C%3E(null, singleton(%22b%22)));%0A        assertEquals(emptySet(), myStore.get(%22A%22));%0A    %7D%0A%0A    private Set%3CString%3E differenceNotNullArgs(final Set%3CString%3E left, final Set%3CString%3E right) %7B%0A        assertNotNull(left);%0A        assertNotNull(right);%0A%0A        final HashSet%3CString%3E strings = new HashSet%3C%3E(left);%0A        strings.removeAll(right);%0A        return strings;%0A    %7D%0A%0A    private Set%3CString%3E unionNotNullArgs(final Set%3CString%3E left, final Set%3CString%3E right) %7B%0A        assertNotNull(left);%0A        assertNotNull(right);%0A%0A        final HashSet%3CString%3E strings = new HashSet%3C%3E();%0A        strings.addAll(left);%0A        strings.addAll(right);%0A        return strings;%0A    %7D%0A%7D%0A

check invariant: oldValue is in the state (#5366)