azagrebin commented on a change in pull request #6777: [FLINK-10461] [State 
Backends, Checkpointing] Speed up download files when restore from DFS
URL: https://github.com/apache/flink/pull/6777#discussion_r228976096
 
 

 ##########
 File path: 
flink-state-backends/flink-statebackend-rocksdb/src/test/java/org/apache/flink/contrib/streaming/state/RocksDBStateDataTransferTest.java
 ##########
 @@ -0,0 +1,143 @@
+/*
+ * 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.contrib.streaming.state;
+
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.core.fs.FileSystem;
+import org.apache.flink.core.fs.Path;
+import org.apache.flink.runtime.state.IncrementalKeyedStateHandle;
+import org.apache.flink.runtime.state.StateHandleID;
+import org.apache.flink.runtime.state.StreamStateHandle;
+import org.apache.flink.runtime.state.memory.ByteStreamStateHandle;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests for RocksDbStateDataTransfer.
+ */
+public class RocksDBStateDataTransferTest {
+       @Rule
+       public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+       /**
+        * Test that the exception arose in the thread pool will rethrow to the 
main thread.
+        */
+       @Test
+       public void testThreadPoolExceptionRethrow() throws Exception {
+               IncrementalKeyedStateHandle stateHandle = 
mock(IncrementalKeyedStateHandle.class);
+
+               SpecifiedException expectedException = new 
SpecifiedException("throw exception while multi thread restore.");
+               StreamStateHandle mockStateHandle = 
mock(StreamStateHandle.class);
+               
when(mockStateHandle.openInputStream()).thenThrow(expectedException);
+
+               Map<StateHandleID, StreamStateHandle> sharedStateHandle = new 
HashMap<>(1);
+               sharedStateHandle.put(new StateHandleID("mock"), 
mockStateHandle);
+               
when(stateHandle.getSharedState()).thenReturn(sharedStateHandle);
+
+               try {
+                       
RocksDbStateDataTransfer.transferAllStateDataToDirectory(stateHandle, new 
Path(temporaryFolder.newFolder().toURI()), 5, new CloseableRegistry());
+                       fail();
+               } catch (Exception e) {
+                       assertEquals(expectedException, 
e.getCause().getCause());
+               }
+       }
+
+       /**
+        * Tests that download files with multi-thread correctly.
+        * @throws Exception
+        */
+       @Test
+       public void testMultiThreadRestoreCorrectly() throws Exception {
+               IncrementalKeyedStateHandle stateHandle = 
mock(IncrementalKeyedStateHandle.class);
+
+               byte[] content1 = new byte[1];
 
 Review comment:
   I would create a list of something like 6 test contexts and use loops over 
them for further actions.
   content length can be also random.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to