parent
4ad92bd544
commit
5734555519
@ -0,0 +1,119 @@
|
|||||||
|
package files;
|
||||||
|
|
||||||
|
import com.olexyn.ensync.Execute;
|
||||||
|
import com.olexyn.ensync.Tools;
|
||||||
|
|
||||||
|
public class FileTest {
|
||||||
|
|
||||||
|
Execute x = new Execute();
|
||||||
|
Tools tools = new Tools();
|
||||||
|
|
||||||
|
private static final String PATH = System.getProperty("user.dir");;
|
||||||
|
|
||||||
|
public static void main(String... args){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simulates user activity on disk.
|
||||||
|
*/
|
||||||
|
void createFiles() throws InterruptedException {
|
||||||
|
StringBuilder sbA = new StringBuilder("a");
|
||||||
|
StringBuilder sbB = new StringBuilder("b");
|
||||||
|
|
||||||
|
// dv (deleted-void)
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// dd
|
||||||
|
tools.writeSbToFile(PATH+"/a/dd", sbA);
|
||||||
|
Thread.sleep(10);
|
||||||
|
tools.writeSbToFile(PATH+"/b/dd", sbB);
|
||||||
|
Thread.sleep(10);Thread.sleep(10);
|
||||||
|
x.execute(new String[]{"rm", PATH+"/a/dd"});
|
||||||
|
Thread.sleep(10);
|
||||||
|
x.execute(new String[]{"rm", PATH+"/b/dd"});
|
||||||
|
Thread.sleep(10);
|
||||||
|
|
||||||
|
// dc
|
||||||
|
tools.writeSbToFile(PATH+"/a/dc", sbA);
|
||||||
|
Thread.sleep(10);
|
||||||
|
x.execute(new String[]{"rm", PATH+"/a/dc"});
|
||||||
|
Thread.sleep(10);
|
||||||
|
tools.writeSbToFile(PATH+"/b/dc", sbB);
|
||||||
|
Thread.sleep(10);
|
||||||
|
|
||||||
|
// dm
|
||||||
|
tools.writeSbToFile(PATH+"/a/dm", sbA);
|
||||||
|
Thread.sleep(10);
|
||||||
|
x.execute(new String[]{"rm", PATH+"/a/dm"});
|
||||||
|
Thread.sleep(10);
|
||||||
|
tools.writeSbToFile(PATH+"/b/dm", sbB);
|
||||||
|
Thread.sleep(10);
|
||||||
|
|
||||||
|
// dv (deleted-void)
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// cd
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// cc
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// cm
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// cv (created-void)
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// md
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// mc
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// mm
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if end-state is as desired.
|
||||||
|
* @throws Exception otherwise.
|
||||||
|
*/
|
||||||
|
void fileTest() throws Exception {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Files where the second (= the newer) file was deleted. Thus both files should not exist in the end-state.
|
||||||
|
String[] arrayToDelete = {"/a/dd", "/b/dd" , "/a/cd", "/b/cd", "/a/md", "/b/md"};
|
||||||
|
for (String path : arrayToDelete){
|
||||||
|
if (new TestableFile(path).exists()) throw new Exception();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Files where the second (= the newer) file was created or modified. Thus both files should contain "b" in the end-state.
|
||||||
|
String[] arrayToB = {"/a/dc", "/b/dc" , "/a/dm", "/b/dm", "/a/cc", "/b/cc"};
|
||||||
|
for (String path : arrayToB){
|
||||||
|
if (!new TestableFile(path).hasContent("b")) throw new Exception();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Assertion Exception
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package files;
|
||||||
|
|
||||||
|
import com.olexyn.ensync.Tools;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class TestableFile extends File {
|
||||||
|
|
||||||
|
Tools tools = new Tools();
|
||||||
|
|
||||||
|
|
||||||
|
public TestableFile(String pathname) {
|
||||||
|
super(pathname);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasContent(String s){
|
||||||
|
|
||||||
|
String line = tools.fileToLines(this).get(0);
|
||||||
|
return line.equals(s);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
### Testing Scenario
|
||||||
|
Test two configs:
|
||||||
|
1. FileOps happen while System is down.
|
||||||
|
1. FileOps happen while System is running.
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
|
||||||
|
| Symbol | Description|
|
||||||
|
---|---
|
||||||
|
`a` | File `a` in directory `A`
|
||||||
|
`b` | File `b` in directory `B`
|
||||||
|
`d(x)` | File `x` is deleted.
|
||||||
|
`c(x)` | File `x` is created.
|
||||||
|
`m(x)` | File `x` is modified.
|
||||||
|
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
| `Given` | | `When` | | `Then` | |
|
||||||
|
---|---|---|---|---|---
|
||||||
|
| `A` | `B`| `A` | `B`|`A` | `B`|
|
||||||
|
| `a` | | `d(a)` | | | |
|
||||||
|
| `a` | `b` | `d(a)` | `d(b)` | | |
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue