flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From StefanRRichter <...@git.apache.org>
Subject [GitHub] flink pull request #4851: [FLINK-7623][tests] Add tests to make sure operato...
Date Fri, 20 Oct 2017 04:46:38 GMT
Github user StefanRRichter commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4851#discussion_r145877847
  
    --- Diff: flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/RestoreStreamTaskTest.java
---
    @@ -0,0 +1,325 @@
    +/*
    + * 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 org.apache.flink.streaming.runtime.tasks;
    +
    +import org.apache.flink.api.common.state.ListState;
    +import org.apache.flink.api.common.state.ListStateDescriptor;
    +import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
    +import org.apache.flink.api.common.typeutils.base.LongSerializer;
    +import org.apache.flink.api.common.typeutils.base.StringSerializer;
    +import org.apache.flink.runtime.checkpoint.CheckpointMetaData;
    +import org.apache.flink.runtime.checkpoint.CheckpointOptions;
    +import org.apache.flink.runtime.checkpoint.OperatorSubtaskState;
    +import org.apache.flink.runtime.checkpoint.StateAssignmentOperation;
    +import org.apache.flink.runtime.checkpoint.TaskStateSnapshot;
    +import org.apache.flink.runtime.jobgraph.OperatorID;
    +import org.apache.flink.runtime.jobgraph.OperatorInstanceID;
    +import org.apache.flink.runtime.operators.testutils.MockInputSplitProvider;
    +import org.apache.flink.runtime.state.StateInitializationContext;
    +import org.apache.flink.runtime.state.StateSnapshotContext;
    +import org.apache.flink.streaming.api.operators.AbstractStreamOperator;
    +import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
    +import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
    +import org.apache.flink.streaming.util.TestHarnessUtil;
    +import org.apache.flink.util.TestLogger;
    +
    +import org.junit.Test;
    +
    +import java.util.Collections;
    +import java.util.Optional;
    +import java.util.concurrent.ConcurrentLinkedQueue;
    +import java.util.concurrent.atomic.AtomicLong;
    +
    +import static org.junit.Assert.assertEquals;
    +
    +/**
    + * Tests ensuring correct behaviour of {@link org.apache.flink.runtime.state.ManagedInitializationContext#isRestored}
    + * method.
    + */
    +public class RestoreStreamTaskTest extends TestLogger {
    +	@Test
    +	public void testRestore() throws Exception {
    +		AcknowledgeStreamMockEnvironment environment1 = processRecords(
    +			new OperatorID(42L, 42L),
    +			new CounterOperator(),
    +			new OperatorID(44L, 44L),
    +			new CounterOperator(),
    +			Optional.empty());
    +
    +		assertEquals(2, environment1.getCheckpointStateHandles().getSubtaskStateMappings().size());
    +
    +		TaskStateSnapshot stateHandles = environment1.getCheckpointStateHandles();
    +
    +		try {
    +			AcknowledgeStreamMockEnvironment environment2 = processRecords(
    +				new OperatorID(42L, 42L),
    +				new RestoreCounterOperator(),
    +				new OperatorID(44L, 44L),
    +				new RestoreCounterOperator(),
    +				Optional.of(stateHandles));
    +
    +			assertEquals(2, RestoreCounterOperator.RESTORE_COUNTER.get());
    +		}
    +		finally {
    +			RestoreCounterOperator.RESTORE_COUNTER.getAndSet(0);
    +		}
    +	}
    +
    +	@Test
    +	public void testRestoreWithNewId() throws Exception {
    +		AcknowledgeStreamMockEnvironment environment1 = processRecords(
    +			new OperatorID(42L, 42L),
    +			new CounterOperator(),
    +			new OperatorID(44L, 44L),
    +			new CounterOperator(),
    +			Optional.empty());
    +
    +		assertEquals(2, environment1.getCheckpointStateHandles().getSubtaskStateMappings().size());
    +
    +		TaskStateSnapshot stateHandles = environment1.getCheckpointStateHandles();
    +
    +		try {
    +			AcknowledgeStreamMockEnvironment environment2 = processRecords(
    +				new OperatorID(4242L, 4242L),
    +				new RestoreCounterOperator(),
    +				new OperatorID(44L, 44L),
    +				new RestoreCounterOperator(),
    +				Optional.of(stateHandles));
    +
    +			assertEquals(1, RestoreCounterOperator.RESTORE_COUNTER.get());
    +		}
    +		finally {
    +			RestoreCounterOperator.RESTORE_COUNTER.getAndSet(0);
    --- End diff --
    
    Maybe just a matter of personal taste, but wouldn't it be easier to simply reset the count
to 0 at the beginning of each test or even have a setup method (or tearDown if you prefer
to reset after the test) for that?


---

Mime
View raw message