18
18
package org .smartdata .server ;
19
19
20
20
/*import org.apache.hadoop.fs.FileStatus;
21
+ import org.apache.hadoop.fs.Path;
21
22
import org.apache.hadoop.hdfs.DFSTestUtil;
22
23
import org.apache.hadoop.hdfs.DistributedFileSystem;
23
- import org.apache.hadoop.fs.Path;
24
24
import org.junit.Assert;
25
25
import org.junit.Test;
26
26
import org.smartdata.admin.SmartAdmin;
@@ -43,8 +43,8 @@ public class TestCopyScheduler extends MiniSmartClusterHarness {
43
43
public void appendMerge() throws Exception {
44
44
waitTillSSMExitSafeMode();
45
45
MetaStore metaStore = ssm.getMetaStore();
46
- SmartAdmin admin = new SmartAdmin(smartContext.getConf());
47
- CmdletManager cmdletManager = ssm.getCmdletManager();
46
+ // SmartAdmin admin = new SmartAdmin(smartContext.getConf());
47
+ // CmdletManager cmdletManager = ssm.getCmdletManager();
48
48
DistributedFileSystem dfs = cluster.getFileSystem();
49
49
final String srcPath = "/src/";
50
50
final String destPath = "/dest/";
@@ -55,7 +55,8 @@ public void appendMerge() throws Exception {
55
55
// Write to src
56
56
for (int i = 0; i < 3; i++) {
57
57
// Create test files
58
- DFSTestUtil.createFile(dfs, new Path(srcPath + i), 1024, (short) 1, 1);
58
+ DFSTestUtil.createFile(dfs, new Path(srcPath + i),
59
+ 1024, (short) 1, 1);
59
60
for (int j = 0; j < 10; j++) {
60
61
DFSTestUtil.appendFile(dfs, new Path(srcPath + i), 1024);
61
62
}
@@ -71,8 +72,8 @@ public void appendMerge() throws Exception {
71
72
public void deleteMerge() throws Exception {
72
73
waitTillSSMExitSafeMode();
73
74
MetaStore metaStore = ssm.getMetaStore();
74
- SmartAdmin admin = new SmartAdmin(smartContext.getConf());
75
- CmdletManager cmdletManager = ssm.getCmdletManager();
75
+ // SmartAdmin admin = new SmartAdmin(smartContext.getConf());
76
+ // CmdletManager cmdletManager = ssm.getCmdletManager();
76
77
DistributedFileSystem dfs = cluster.getFileSystem();
77
78
final String srcPath = "/src/";
78
79
final String destPath = "/dest/";
@@ -83,7 +84,8 @@ public void deleteMerge() throws Exception {
83
84
// Write to src
84
85
for (int i = 0; i < 3; i++) {
85
86
// Create test files
86
- DFSTestUtil.createFile(dfs, new Path(srcPath + i), 1024, (short) 1, 1);
87
+ DFSTestUtil.createFile(dfs, new Path(srcPath + i),
88
+ 1024, (short) 1, 1);
87
89
do {
88
90
Thread.sleep(500);
89
91
} while (!dfs.isFileClosed(new Path(srcPath + i)));
@@ -106,7 +108,7 @@ public void deleteMerge() throws Exception {
106
108
public void renameMerge() throws Exception {
107
109
waitTillSSMExitSafeMode();
108
110
MetaStore metaStore = ssm.getMetaStore();
109
- SmartAdmin admin = new SmartAdmin(smartContext.getConf());
111
+ // SmartAdmin admin = new SmartAdmin(smartContext.getConf());
110
112
DistributedFileSystem dfs = cluster.getFileSystem();
111
113
final String srcPath = "/src/";
112
114
final String destPath = "/dest/";
@@ -117,8 +119,10 @@ public void renameMerge() throws Exception {
117
119
// Write to src
118
120
for (int i = 0; i < 3; i++) {
119
121
// Create test files
120
- DFSTestUtil.createFile(dfs, new Path(srcPath + i), 1024, (short) 1, 1);
121
- dfs.rename(new Path(srcPath + i), new Path(srcPath + i + 10));
122
+ DFSTestUtil.createFile(dfs, new Path(srcPath + i),
123
+ 1024, (short) 1, 1);
124
+ dfs.rename(new Path(srcPath + i),
125
+ new Path(srcPath + i + 10));
122
126
// Rename target ends with 10
123
127
DFSTestUtil.appendFile(dfs, new Path(srcPath + i + 10), 1024);
124
128
}
@@ -138,11 +142,12 @@ public void renameMerge() throws Exception {
138
142
public void failRetry() throws Exception {
139
143
waitTillSSMExitSafeMode();
140
144
MetaStore metaStore = ssm.getMetaStore();
141
- CmdletManager cmdletManager = ssm.getCmdletManager();
145
+ // CmdletManager cmdletManager = ssm.getCmdletManager();
142
146
SmartAdmin admin = new SmartAdmin(smartContext.getConf());
143
147
long ruleId =
144
148
admin.submitRule(
145
- "file: every 1s | path matches \"/src/*\"| sync -dest /dest/", RuleState.ACTIVE);
149
+ "file: every 1s | path matches \"/src/*\"| sync -dest /dest/",
150
+ RuleState.ACTIVE);
146
151
FileDiff fileDiff = new FileDiff(FileDiffType.RENAME, FileDiffState.PENDING);
147
152
fileDiff.setSrc("/src/1");
148
153
fileDiff.getParameters().put("-dest", "/src/2");
@@ -171,20 +176,23 @@ public void testForceSync() throws Exception {
171
176
// Write to src
172
177
for (int i = 0; i < 3; i++) {
173
178
// Create test files
174
- DFSTestUtil.createFile(dfs, new Path(srcPath + i), 1024, (short) 1, 1);
179
+ DFSTestUtil.createFile(dfs, new Path(srcPath + i),
180
+ 1024, (short) 1, 1);
175
181
}
176
182
177
183
for (int i = 0; i < 3; i++) {
178
184
// Create test files
179
- DFSTestUtil.createFile(dfs, new Path(destPath + i + 5), 1024, (short) 1, 1);
185
+ DFSTestUtil.createFile(dfs, new Path(destPath + i + 5),
186
+ 1024, (short) 1, 1);
180
187
}
181
188
182
189
// Clear file diffs
183
190
metaStore.deleteAllFileDiff();
184
191
// Submit rules and trigger forceSync
185
192
long ruleId =
186
193
admin.submitRule(
187
- "file: every 2s | path matches \"/src/*\"| sync -dest /dest/", RuleState.ACTIVE);
194
+ "file: every 2s | path matches \"/src/*\"| sync -dest /dest/",
195
+ RuleState.ACTIVE);
188
196
Thread.sleep(1000);
189
197
Assert.assertTrue(metaStore.getFileDiffs(FileDiffState.PENDING).size() > 0);
190
198
}
@@ -200,14 +208,17 @@ public void batchSync() throws Exception {
200
208
FileInfo fileInfo;
201
209
long now = System.currentTimeMillis();
202
210
for (int i = 0; i < 100; i++) {
203
- fileInfo = new FileInfo(srcPath + i, i, 1024, false, (short)3,
204
- 1024, now, now, (short) 1, null, null, (byte)3);
211
+ fileInfo = new FileInfo(srcPath + i, i,
212
+ 1024, false, (short) 3,
213
+ 1024, now, now, (short) 1,
214
+ null, null, (byte) 3);
205
215
metaStore.insertFile(fileInfo);
206
216
Thread.sleep(100);
207
217
}
208
218
long ruleId =
209
219
admin.submitRule(
210
- "file: every 2s | path matches \"/src/*\"| sync -dest /dest/", RuleState.ACTIVE);
220
+ "file: every 2s | path matches \"/src/*\"| sync -dest /dest/",
221
+ RuleState.ACTIVE);
211
222
Thread.sleep(2200);
212
223
do {
213
224
Thread.sleep(1000);
@@ -222,15 +233,17 @@ public void testDelete() throws Exception {
222
233
SmartAdmin admin = new SmartAdmin(smartContext.getConf());
223
234
long ruleId =
224
235
admin.submitRule(
225
- "file: every 2s | path matches \"/src/*\"| sync -dest /dest/", RuleState.ACTIVE);
236
+ "file: every 2s | path matches \"/src/*\"| sync -dest /dest/",
237
+ RuleState.ACTIVE);
226
238
FileDiff fileDiff = new FileDiff(FileDiffType.DELETE, FileDiffState.PENDING);
227
239
fileDiff.setSrc("/src/1");
228
240
metaStore.insertFileDiff(fileDiff);
229
241
Thread.sleep(1200);
230
242
do {
231
243
Thread.sleep(1000);
232
244
} while (admin.getRuleInfo(ruleId).getNumCmdsGen() == 0);
233
- Assert.assertTrue(cmdletManager.listNewCreatedActions("sync", 0).size() > 0);
245
+ Assert.assertTrue(cmdletManager
246
+ .listNewCreatedActions("sync", 0).size() > 0);
234
247
}
235
248
236
249
@Test(timeout = 60000)
@@ -241,7 +254,8 @@ public void testRename() throws Exception {
241
254
SmartAdmin admin = new SmartAdmin(smartContext.getConf());
242
255
long ruleId =
243
256
admin.submitRule(
244
- "file: every 2s | path matches \"/src/*\"| sync -dest /dest/", RuleState.ACTIVE);
257
+ "file: every 2s | path matches \"/src/*\"| sync -dest /dest/",
258
+ RuleState.ACTIVE);
245
259
FileDiff fileDiff = new FileDiff(FileDiffType.RENAME, FileDiffState.PENDING);
246
260
fileDiff.setSrc("/src/1");
247
261
fileDiff.getParameters().put("-dest", "/src/2");
@@ -250,7 +264,8 @@ public void testRename() throws Exception {
250
264
do {
251
265
Thread.sleep(1000);
252
266
} while (admin.getRuleInfo(ruleId).getNumCmdsGen() == 0);
253
- Assert.assertTrue(cmdletManager.listNewCreatedActions("sync", 0).size() > 0);
267
+ Assert.assertTrue(cmdletManager
268
+ .listNewCreatedActions("sync", 0).size() > 0);
254
269
}
255
270
256
271
@Test
@@ -266,10 +281,12 @@ public void testMeta() throws Exception {
266
281
dfs.mkdirs(new Path(destPath));
267
282
long ruleId =
268
283
admin.submitRule(
269
- "file: every 2s | path matches \"/src/*\"| sync -dest /dest/", RuleState.ACTIVE);
284
+ "file: every 2s | path matches \"/src/*\"| sync -dest /dest/",
285
+ RuleState.ACTIVE);
270
286
Thread.sleep(4200);
271
287
// Write to src
272
- DFSTestUtil.createFile(dfs, new Path(srcPath + 1), 1024, (short) 1, 1);
288
+ DFSTestUtil.createFile(dfs, new Path(srcPath + 1),
289
+ 1024, (short) 1, 1);
273
290
Thread.sleep(1000);
274
291
FileDiff fileDiff = new FileDiff(FileDiffType.METADATA, FileDiffState.PENDING);
275
292
fileDiff.setSrc("/src/1");
@@ -306,12 +323,14 @@ public void testCache() throws Exception {
306
323
// Write to src
307
324
for (int i = 0; i < 3; i++) {
308
325
// Create test files
309
- DFSTestUtil.createFile(dfs, new Path(srcPath + i), 1024, (short) 1, 1);
326
+ DFSTestUtil.createFile(dfs, new Path(srcPath + i),
327
+ 1024, (short) 1, 1);
310
328
}
311
329
do {
312
330
Thread.sleep(1000);
313
331
} while (admin.getRuleInfo(ruleId).getNumCmdsGen() <= 2);
314
- List<ActionInfo> actionInfos = cmdletManager.listNewCreatedActions("sync", 0);
332
+ List<ActionInfo> actionInfos = cmdletManager
333
+ .listNewCreatedActions("sync", 0);
315
334
Assert.assertTrue(actionInfos.size() >= 3);
316
335
Thread.sleep(20000);
317
336
}
@@ -341,12 +360,14 @@ public void testWithSyncRule() throws Exception {
341
360
// Write to src
342
361
for (int i = 0; i < 3; i++) {
343
362
// Create test files
344
- DFSTestUtil.createFile(dfs, new Path(srcPath + i), 1024, (short) 1, 1);
363
+ DFSTestUtil.createFile(dfs, new Path(srcPath + i),
364
+ 1024, (short) 1, 1);
345
365
}
346
366
do {
347
367
Thread.sleep(1000);
348
368
} while (admin.getRuleInfo(ruleId).getNumCmdsGen() <= 2);
349
- List<ActionInfo> actionInfos = cmdletManager.listNewCreatedActions("sync", 0);
369
+ List<ActionInfo> actionInfos = cmdletManager
370
+ .listNewCreatedActions("sync", 0);
350
371
Assert.assertTrue(actionInfos.size() >= 3);
351
372
do {
352
373
Thread.sleep(800);
@@ -376,7 +397,8 @@ public void testCopy() throws Exception {
376
397
// Write to src
377
398
for (int i = 0; i < 3; i++) {
378
399
// Create test files
379
- DFSTestUtil.createFile(dfs, new Path(srcPath + i), 1024, (short) 1, 1);
400
+ DFSTestUtil.createFile(dfs, new Path(srcPath + i),
401
+ 1024, (short) 1, 1);
380
402
}
381
403
Thread.sleep(1000);
382
404
CmdletManager cmdletManager = ssm.getCmdletManager();
@@ -386,7 +408,8 @@ public void testCopy() throws Exception {
386
408
cmdletManager.submitCmdlet(
387
409
"sync -file /src/" + i + " -src " + srcPath + " -dest " + destPath);
388
410
}
389
- List<ActionInfo> actionInfos = cmdletManager.listNewCreatedActions("sync", 0);
411
+ List<ActionInfo> actionInfos = cmdletManager
412
+ .listNewCreatedActions("sync", 0);
390
413
Assert.assertTrue(actionInfos.size() >= 3);
391
414
do {
392
415
Thread.sleep(1000);
@@ -399,6 +422,45 @@ public void testCopy() throws Exception {
399
422
}
400
423
}
401
424
425
+ @Test(timeout = 40000)
426
+ public void testEmpyDelete() throws Exception {
427
+ // Delete files not exist on standby cluster
428
+ waitTillSSMExitSafeMode();
429
+ MetaStore metaStore = ssm.getMetaStore();
430
+ // metaStore.deleteAllFileDiff();
431
+ // metaStore.deleteAllFileInfo();
432
+ // metaStore.deleteAllCmdlets();
433
+ // metaStore.deleteAllActions();
434
+ DistributedFileSystem dfs = cluster.getFileSystem();
435
+ final String srcPath = "/src/";
436
+ final String destPath = "/dest/";
437
+ // Write to src
438
+ for (int i = 0; i < 3; i++) {
439
+ // Create test files
440
+ DFSTestUtil.createFile(dfs, new Path(srcPath + i),
441
+ 1024, (short) 1, 1);
442
+ }
443
+ Thread.sleep(500);
444
+ BackUpInfo backUpInfo = new BackUpInfo(1L, srcPath, destPath, 100);
445
+ metaStore.insertBackUpInfo(backUpInfo);
446
+ dfs.mkdirs(new Path(srcPath));
447
+ dfs.mkdirs(new Path(destPath));
448
+ Thread.sleep(100);
449
+ for (int i = 0; i < 3; i++) {
450
+ // delete test files on primary cluster
451
+ dfs.delete(new Path(srcPath + i), false);
452
+ }
453
+
454
+ Thread.sleep(2000);
455
+ CmdletManager cmdletManager = ssm.getCmdletManager();
456
+ // Submit sync action
457
+ for (int i = 0; i < 3; i++) {
458
+ // Create test files
459
+ cmdletManager.submitCmdlet(
460
+ "sync -file /src/" + i + " -src " + srcPath + " -dest " + destPath);
461
+ }
462
+ }
463
+
402
464
@Test(timeout = 40000)
403
465
public void testCopyDelete() throws Exception {
404
466
waitTillSSMExitSafeMode();
@@ -417,7 +479,8 @@ public void testCopyDelete() throws Exception {
417
479
// Write to src
418
480
for (int i = 0; i < 3; i++) {
419
481
// Create test files
420
- DFSTestUtil.createFile(dfs, new Path(srcPath + i), 1024, (short) 1, 1);
482
+ DFSTestUtil.createFile(dfs, new Path(srcPath + i),
483
+ 1024, (short) 1, 1);
421
484
dfs.delete(new Path(srcPath + i), false);
422
485
}
423
486
@@ -429,13 +492,5 @@ public void testCopyDelete() throws Exception {
429
492
cmdletManager.submitCmdlet(
430
493
"sync -file /src/" + i + " -src " + srcPath + " -dest " + destPath);
431
494
}
432
- List<ActionInfo> actionInfos = cmdletManager.listNewCreatedActions("sync", 0);
433
- Assert.assertTrue(actionInfos.size() >= 3);
434
- Thread.sleep(3000);
435
- for (int i = 0; i < 3; i++) {
436
- // Write 10 files
437
- Assert.assertFalse(dfs.exists(new Path(destPath + i)));
438
- System.out.printf("File %d is copied.\n", i);
439
- }
440
495
}
441
496
}*/
0 commit comments