| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ca1ebdc commit 8e1de20
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -142,13 +142,7 @@ public Boolean call() { | |||
| 142 | 142 | boolean success = true; | |
| 143 | 143 | try { | |
| 144 | 144 | do { // We loop getting and processing work. | |
| 145 | - try { | ||
| 146 | - LOG.debug("Thread starting getAndPerformWork."); | ||
| 147 | - success = worker.getAndPerformWork(); | ||
| 148 | - LOG.debug("{} processing one WorkItem.", success ? "Finished" : "Failed"); | ||
| 149 | - } catch (IOException e) { // If there is a problem getting work. | ||
| 150 | - success = false; | ||
| 151 | - } | ||
| 145 | + success = doWork(); | ||
| 152 | 146 | if (success) { | |
| 153 | 147 | backOff.reset(); | |
| 154 | 148 | } | |
@@ -158,10 +152,27 @@ public Boolean call() { | |||
| 158 | 152 | LOG.error("Already tried several attempts at working on tasks. Aborting.", e); | |
| 159 | 153 | } catch (InterruptedException e) { | |
| 160 | 154 | LOG.error("Interrupted during thread execution or sleep.", e); | |
| 155 | + } catch (Throwable t) { | ||
| 156 | + LOG.error("Thread {} died.", Thread.currentThread().getId(), t); | ||
| 161 | 157 | } | |
| 162 | 158 | return false; | |
| 163 | 159 | } | |
| 164 | 160 | ||
| 161 | + private boolean doWork() { | ||
| 162 | + try { | ||
| 163 | + LOG.debug("Thread starting getAndPerformWork."); | ||
| 164 | + boolean success = worker.getAndPerformWork(); | ||
| 165 | + LOG.debug("{} processing one WorkItem.", success ? "Finished" : "Failed"); | ||
| 166 | + return success; | ||
| 167 | + } catch (IOException e) { // If there is a problem getting work. | ||
| 168 | + LOG.debug("There was a problem getting work.", e); | ||
| 169 | + return false; | ||
| 170 | + } catch (Exception e) { // These exceptions are caused by bugs within the SDK | ||
| 171 | + LOG.error("There was an unhandled error caused by the Dataflow SDK.", e); | ||
| 172 | + return false; | ||
| 173 | + } | ||
| 174 | + } | ||
| 175 | + | ||
| 165 | 176 | private final DataflowWorker worker; | |
| 166 | 177 | private final Sleeper sleeper; | |
| 167 | 178 | private final BackOff backOff; | |
@@ -183,6 +194,7 @@ static void processWork(DataflowWorkerHarnessOptions pipelineOptions, | |||
| 183 | 194 | LOG.debug("Waiting for {} worker threads", numThreads); | |
| 184 | 195 | // We wait forever unless there is a big problem. | |
| 185 | 196 | executor.invokeAll(tasks); | |
| 197 | + LOG.error("All threads died."); | ||
| 186 | 198 | } | |
| 187 | 199 | ||
| 188 | 200 | static DataflowWorker create(DataflowWorkerHarnessOptions options) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -94,10 +94,8 @@ public void setUp() throws Exception { | |||
| 94 | 94 | pipelineOptions.setGcpCredential(new TestCredential()); | |
| 95 | 95 | } | |
| 96 | 96 | ||
| 97 | - @Test | ||
| 98 | - public void testThatWeRetryIfTaskExecutionFailAgainAndAgain() throws Exception { | ||
| 97 | + public void runTestThatWeRetryIfTaskExecutionFailsAgainAndAgain() throws Exception { | ||
| 99 | 98 | final int numWorkers = Math.max(Runtime.getRuntime().availableProcessors(), 1); | |
| 100 | - when(mockDataflowWorker.getAndPerformWork()).thenReturn(false); | ||
| 101 | 99 | final AtomicInteger sleepCount = new AtomicInteger(0); | |
| 102 | 100 | final AtomicInteger illegalIntervalCount = new AtomicInteger(0); | |
| 103 | 101 | DataflowWorkerHarness.processWork( | |
@@ -124,6 +122,24 @@ public void sleep(long millis) throws InterruptedException { | |||
| 124 | 122 | assertEquals(0, illegalIntervalCount.get()); | |
| 125 | 123 | } | |
| 126 | 124 | ||
| 125 | + @Test | ||
| 126 | + public void testThatWeRetryIfTaskExecutionFailAgainAndAgain() throws Exception { | ||
| 127 | + when(mockDataflowWorker.getAndPerformWork()).thenReturn(false); | ||
| 128 | + runTestThatWeRetryIfTaskExecutionFailsAgainAndAgain(); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + @Test | ||
| 132 | + public void testThatWeRetryIfTaskExecutionFailAgainAndAgainByIOException() throws Exception { | ||
| 133 | + when(mockDataflowWorker.getAndPerformWork()).thenThrow(new IOException()); | ||
| 134 | + runTestThatWeRetryIfTaskExecutionFailsAgainAndAgain(); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + @Test | ||
| 138 | + public void testThatWeRetryIfTaskExecutionFailAgainAndAgainByUnknownException() throws Exception { | ||
| 139 | + when(mockDataflowWorker.getAndPerformWork()).thenThrow(new RuntimeException()); | ||
| 140 | + runTestThatWeRetryIfTaskExecutionFailsAgainAndAgain(); | ||
| 141 | + } | ||
| 142 | + | ||
| 127 | 143 | @Test | |
| 128 | 144 | public void testNumberOfWorkerHarnessThreadsIsHonored() throws Exception { | |
| 129 | 145 | final int expectedNumberOfThreads = 5; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments