Skip to content

Commit

Permalink
file sync - unit test for choosing target directory via script based …
Browse files Browse the repository at this point in the history
…on size
  • Loading branch information
chenson42 committed May 24, 2013
1 parent d1d0253 commit 163e1e0
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 35 deletions.
Expand Up @@ -12,11 +12,17 @@ public class FileSyncTest extends AbstractTest {
File allSvrSourceInitialLoadFile = new File(allSvrSourceDir, "initialload.txt");
File allClntTargetDir = new File("target/fs_clnt/all");
File allClntTargetInitialLoadFile = new File(allClntTargetDir, "initialload.txt");

File pingbackServerDir = new File("target/fs_svr/ping_back");
File pingbackClientDir = new File("target/fs_clnt/ping_back");

File[] allDirs = new File[] { allSvrSourceDir, allClntTargetDir, pingbackClientDir, pingbackServerDir };
File chooseTargetServerDir = new File("target/fs_svr/choose_target");
File chooseTargetClientDirA = new File("target/fs_clnt/choose_target/a");
File chooseTargetClientDirB = new File("target/fs_clnt/choose_target/b");

File[] allDirs = new File[] { allSvrSourceDir, allClntTargetDir, pingbackClientDir,
pingbackServerDir, chooseTargetClientDirA, chooseTargetClientDirB,
chooseTargetServerDir };

@Override
protected String[] getGroupNames() {
Expand All @@ -27,29 +33,36 @@ protected String[] getGroupNames() {
protected void test(ISymmetricEngine rootServer, ISymmetricEngine clientServer)
throws Exception {
createDirsAndInitialFiles();

loadConfigAndRegisterNode("client", "server");

pullFiles();

testInitialLoadFromServerToClient(rootServer, clientServer);

testPullAllFromServerToClient(rootServer, clientServer);

testPingback();

testChooseTargetDirectory(rootServer, clientServer);

}

protected void testInitialLoadFromServerToClient(ISymmetricEngine rootServer,
ISymmetricEngine clientServer) throws Exception {
Assert.assertFalse("The initial load file should not exist at the client", allClntTargetInitialLoadFile.exists());
Assert.assertTrue("The initial load file should exist at the server", allSvrSourceInitialLoadFile.exists());
pullFiles();
Assert.assertFalse("The initial load file should not exist at the client", allClntTargetInitialLoadFile.exists());
Assert.assertTrue("The initial load file should exist at the server", allSvrSourceInitialLoadFile.exists());
rootServer.reloadNode(clientServer.getNodeService().findIdentityNodeId(), "unit_test");
pullFiles();
Assert.assertTrue("The initial load file should exist at the client", allClntTargetInitialLoadFile.exists());
Assert.assertFalse("The initial load file should not exist at the client",
allClntTargetInitialLoadFile.exists());
Assert.assertTrue("The initial load file should exist at the server",
allSvrSourceInitialLoadFile.exists());
pullFiles();
Assert.assertFalse("The initial load file should not exist at the client",
allClntTargetInitialLoadFile.exists());
Assert.assertTrue("The initial load file should exist at the server",
allSvrSourceInitialLoadFile.exists());
rootServer.reloadNode(clientServer.getNodeService().findIdentityNodeId(), "unit_test");
pullFiles();
Assert.assertTrue("The initial load file should exist at the client",
allClntTargetInitialLoadFile.exists());
}

protected void testPullAllFromServerToClient(ISymmetricEngine rootServer,
Expand All @@ -70,38 +83,74 @@ protected void testPullAllFromServerToClient(ISymmetricEngine rootServer,

Assert.assertFalse(allFile1Target.exists());
}

protected void testPingback() throws Exception {
File serverFile = new File(pingbackServerDir, "ping.txt");
Assert.assertFalse(serverFile.exists());

Assert.assertFalse("Should not have pulled any files", pullFiles());
File clientFile = new File(pingbackClientDir, "ping.txt");

File clientFile = new File(pingbackClientDir, "ping.txt");
FileUtils.write(clientFile, "test");

Assert.assertTrue(pushFiles());

Assert.assertTrue(serverFile.exists());

Assert.assertFalse("Should not have pulled any files", pullFiles());

}

protected void testChooseTargetDirectory() {

}

protected void testUseExpressionInPathToRoute() {


protected void testChooseTargetDirectory(ISymmetricEngine rootServer,
ISymmetricEngine clientServer) throws Exception {
File one = new File(chooseTargetServerDir, "1.txt");
File two = new File(chooseTargetServerDir, "2.txt");
File three = new File(chooseTargetServerDir, "3.txt");

File clientOneA = new File(chooseTargetClientDirA, "1.txt");
File clientOneB = new File(chooseTargetClientDirB, "1.txt");

File clientTwoA = new File(chooseTargetClientDirA, "2.txt");
File clientTwoB = new File(chooseTargetClientDirB, "2.txt");


File clientThreeA = new File(chooseTargetClientDirA, "3.txt");
File clientThreeB = new File(chooseTargetClientDirB, "3.txt");

Assert.assertFalse(clientOneA.exists());
Assert.assertFalse(clientOneB.exists());

FileUtils.write(one, "abc");

pullFiles();

Assert.assertTrue(clientOneA.exists());
Assert.assertFalse(clientOneB.exists());

FileUtils.write(two, "abcdef");

pullFiles();

Assert.assertFalse(clientTwoA.exists());
Assert.assertTrue(clientTwoB.exists());

FileUtils.write(three, "abcdef");

pullFiles();

Assert.assertTrue(clientThreeA.exists());
Assert.assertFalse(clientThreeB.exists());



}

protected boolean pullFiles() {
getWebServer("server").getEngine().getFileSyncService().trackChanges(true);
getWebServer("server").getEngine().getRouterService().routeData(true);
return pullFiles("client");
}

protected boolean pushFiles() {
getWebServer("client").getEngine().getFileSyncService().trackChanges(true);
getWebServer("client").getEngine().getRouterService().routeData(true);
Expand All @@ -113,7 +162,7 @@ protected void createDirsAndInitialFiles() throws Exception {
FileUtils.deleteDirectory(dir);
dir.mkdirs();
}

FileUtils.write(allSvrSourceInitialLoadFile, "Initial Load Data");
}

Expand Down
Expand Up @@ -130,10 +130,10 @@ table,SYM_FILE_TRIGGER
insert,"all","target/fs_svr/all","0",,,"1","1","1",,,"2013-05-19 10:13:26.966","unit_test","2013-05-19 10:13:26.966"
insert,"create_only","target/fs_svr/create_only","0",,,"1","0","0",,,"2013-05-19 10:13:26.966","unit_test","2013-05-19 10:13:26.966"
insert,"all_recursive","target/fs_svr/all_recursive","1",,,"1","1","1",,,"2013-05-19 10:13:26.966","unit_test","2013-05-19 10:13:26.966"
insert,".csv only","target/fs_svr/csv_only","0","*.txt",,"1","1","1",,,"2013-05-19 10:13:26.966","unit_test","2013-05-19 10:13:26.966"
insert,"csv_only","target/fs_svr/csv_only","0","*.txt",,"1","1","1",,,"2013-05-19 10:13:26.966","unit_test","2013-05-19 10:13:26.966"
insert,"choose_target","target/fs_svr/choose_target","0",,,"1","1","1","
a = new java.io.File(\"target/fs_client/a\");
b = new java.io.File(\"target/fs_client/b\");
a = new java.io.File(\"target/fs_clnt/choose_target/a\");
b = new java.io.File(\"target/fs_clnt/choose_target/b\");
if (org.apache.commons.io.FileUtils.sizeOfDirectory(a) > org.apache.commons.io.FileUtils.sizeOfDirectory(b)) {
targetBaseDir = b;
} else {
Expand All @@ -149,7 +149,7 @@ table,SYM_FILE_TRIGGER_ROUTER
insert,"all","server_2_client","1","1","target/fs_clnt/all",,"SOURCE_WINS","2013-05-19 13:52:16.390","unit_test","2013-05-19 13:52:16.390"
insert,"create_only","server_2_client","1","1","target/fs_clnt/create_only",,"SOURCE_WINS","2013-05-19 13:53:45.635","unit_test","2013-05-19 13:53:45.635"
insert,"all_recursive","server_2_client","1","1","target/fs_clnt/all_recursive",,"SOURCE_WINS","2013-05-19 13:53:45.635","unit_test","2013-05-19 13:53:45.635"
insert,".csv only","server_2_client","1","1","target/fs_clnt/csv_only",,"SOURCE_WINS","2013-05-19 13:53:45.635","unit_test","2013-05-19 13:53:45.635"
insert,"csv_only","server_2_client","1","1","target/fs_clnt/csv_only",,"SOURCE_WINS","2013-05-19 13:53:45.635","unit_test","2013-05-19 13:53:45.635"
insert,"choose_target","server_2_client","1","1","target/fs_clnt/choose_target",,"SOURCE_WINS","2013-05-19 13:53:45.635","unit_test","2013-05-19 13:53:45.635"
insert,"client_src","client_2_server","1","1","target/fs_svr/client_src",,"SOURCE_WINS","2013-05-19 13:56:18.456","unit_test","2013-05-19 13:56:18.456"
insert,"ping_back_svr","server_2_client","1","1","target/fs_clnt/ping_back",,"SOURCE_WINS","2013-05-19 13:59:05.366","unit_test","2013-05-19 13:59:05.366"
Expand Down

0 comments on commit 163e1e0

Please sign in to comment.