40
40
import org .mockito .invocation .InvocationOnMock ;
41
41
import org .mockito .stubbing .Answer ;
42
42
import org .testng .Assert ;
43
+ import org .testng .annotations .AfterMethod ;
43
44
import org .testng .annotations .BeforeClass ;
44
45
import org .testng .annotations .BeforeMethod ;
45
46
import org .testng .annotations .Test ;
@@ -125,6 +126,13 @@ public Object getNativeObject() {
125
126
when (mockRecord .getSchema ()).thenAnswer ((Answer <Schema <KeyValue <String , Foobar >>>) invocation -> kvSchema );
126
127
}
127
128
129
+ @ AfterMethod
130
+ public void tearDown () throws Exception {
131
+ if (cluster != null ) {
132
+ cluster .stop ();
133
+ }
134
+ }
135
+
128
136
@ Test
129
137
public void openTest () throws Exception {
130
138
map .put ("filePrefix" , "TopicA" );
@@ -147,7 +155,6 @@ public void openTest() throws Exception {
147
155
Assert .assertTrue (client .exists (alluxioTmpURI ));
148
156
149
157
sink .close ();
150
- cluster .stop ();
151
158
}
152
159
153
160
@ Test
@@ -186,11 +193,36 @@ public Object getNativeObject() {
186
193
Assert .assertTrue (client .exists (alluxioTmpURI ));
187
194
188
195
List <URIStatus > listAlluxioDirStatus = client .listStatus (alluxioURI );
189
-
190
196
List <String > pathList = listAlluxioDirStatus .stream ().map (URIStatus ::getPath ).collect (Collectors .toList ());
191
-
192
197
Assert .assertEquals (pathList .size (), 2 );
193
198
199
+ for (String path : pathList ) {
200
+ if (path .contains ("tmp" )) {
201
+ // Ensure that the temporary file is rotated and the directory is empty
202
+ Assert .assertEquals (path , "/pulsar/tmp" );
203
+ } else {
204
+ // Ensure that all rotated files conform the naming convention
205
+ Assert .assertTrue (path .startsWith ("/pulsar/TopicA-" ));
206
+ }
207
+ }
208
+
209
+ // Ensure the subsequent writes are also successful
210
+ sink .write (() -> new GenericObject () {
211
+ @ Override
212
+ public SchemaType getSchemaType () {
213
+ return SchemaType .KEY_VALUE ;
214
+ }
215
+
216
+ @ Override
217
+ public Object getNativeObject () {
218
+ return new KeyValue <>((String ) fooBar .getField ("address" ), fooBar );
219
+ }
220
+ });
221
+
222
+ listAlluxioDirStatus = client .listStatus (alluxioURI );
223
+ pathList = listAlluxioDirStatus .stream ().map (URIStatus ::getPath ).collect (Collectors .toList ());
224
+ Assert .assertEquals (pathList .size (), 3 );
225
+
194
226
for (String path : pathList ) {
195
227
if (path .contains ("tmp" )) {
196
228
Assert .assertEquals (path , "/pulsar/tmp" );
@@ -200,7 +232,6 @@ public Object getNativeObject() {
200
232
}
201
233
202
234
sink .close ();
203
- cluster .stop ();
204
235
}
205
236
206
237
private LocalAlluxioCluster setupSingleMasterCluster () throws Exception {
0 commit comments