Commit fca0cfe
committed
simplify BlockingProcessStreamReader; fix tests
Update #1429.
This commit simplifies the main run() method.
Previous implementation checks whether the underlying Reader is ready to read
then either reads a line or sleeps,
catching InterruptedException to watch for any thread interruption.
There are subtle difficulties with this approach:
- Even if the underlying Reader is ready to read, it might not have
enough bytes to form a line. It might still block.
- It's not necessary to sleep. If the thread is interrupted while
reading. It should throw InterruptedIOException.
The method now reads in a loop, waiting for either exceptions or EOF.
The test class implements a mock Logger that logs to a data structure.
It then verifies that the data structure holds appropriate logs.
As implemented, this can cause a race, as two threads,
the writer and the verifier, run concurrently.
This commit fixes this by waiting for the writing thread to terminate
before verifying.1 parent 0838c41 commit fca0cfe
File tree
2 files changed
+12
-39
lines changed- google-cloud-core/src
- main/java/com/google/cloud/testing
- test/java/com/google/cloud/testing
2 files changed
+12
-39
lines changedLines changed: 10 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | 38 | | |
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
43 | 42 | | |
44 | 43 | | |
45 | 44 | | |
46 | | - | |
47 | 45 | | |
48 | 46 | | |
49 | 47 | | |
| |||
64 | 62 | | |
65 | 63 | | |
66 | 64 | | |
67 | | - | |
68 | | - | |
69 | 65 | | |
70 | 66 | | |
71 | 67 | | |
72 | 68 | | |
73 | 69 | | |
74 | 70 | | |
75 | 71 | | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
88 | 78 | | |
89 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
90 | 83 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | 84 | | |
96 | 85 | | |
97 | 86 | | |
| |||
Lines changed: 2 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 90 | + | |
95 | 91 | | |
96 | 92 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | 93 | | |
102 | 94 | | |
103 | 95 | | |
| |||
106 | 98 | | |
107 | 99 | | |
108 | 100 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
| 101 | + | |
114 | 102 | | |
115 | 103 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | 104 | | |
121 | 105 | | |
122 | 106 | | |
| |||
0 commit comments