/** * Initializes the redeployment cycle. In "redeploy mode", the application is launched as background, and is * restarted after every change. A {@link Watcher} instance is responsible for monitoring files and triggering the * redeployment. */ protected synchronized void initializeRedeployment() { if (watcher != null) { throw new IllegalStateException("Redeployment already started ? The watcher already exists"); } // Compute the application id. We append "-redeploy" to ease the identification in the process list. vertxApplicationBackgroundId = UUID.randomUUID().toString() + "-redeploy"; watcher = new Watcher(getCwd(), redeploy, this::startAsBackgroundApplication, // On deploy this::stopBackgroundApplication, // On undeploy onRedeployCommand, // In between command redeployGracePeriod, // The redeploy grace period redeployScanPeriod); // The redeploy scan period // Close the watcher when the JVM is terminating. // Notice that the vert.x finalizer is not registered when we run in redeploy mode. Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { shutdownRedeployment(); } }); // Start the watching process, it triggers the initial deployment. watcher.watch(); }
@Test public void testWithANonMatchingFile() throws IOException, InterruptedException { watcher.watch(); // Initial deployment assertWaitUntil(() -> deploy.get() == 1); File file = new File(root, "foo.nope"); file.createNewFile(); Thread.sleep(500); assertThat(undeploy.get()).isEqualTo(0); assertThat(deploy.get()).isEqualTo(1); }
@Test public void testFileDeletion() throws IOException, InterruptedException { File file = new File(root, "foo.txt"); file.createNewFile(); watcher.watch(); // Initial deployment assertWaitUntil(() -> deploy.get() == 1); // Wait until the file monitoring is set up (ugly, but I don't know any way to detect this). Thread.sleep(500); file.delete(); // undeployment followed by redeployment assertWaitUntil(() -> undeploy.get() == 1 && deploy.get() == 2); }
@Test public void testFileAddition() throws IOException { watcher.watch(); // Initial deployment assertWaitUntil(() -> deploy.get() == 1); File file = new File(root, "foo.txt"); file.createNewFile(); // undeployment followed by redeployment assertWaitUntil(() -> undeploy.get() == 1 && deploy.get() == 2); }
@Test public void testFileModification() throws IOException, InterruptedException { File file = new File(root, "foo.txt"); watcher.watch(); // Initial deployment assertWaitUntil(() -> deploy.get() == 1); file.createNewFile(); assertWaitUntil(() -> deploy.get() == 2); // Simulate a 'touch', we wait more than a second to avoid being in the same second as the creation. This is because // some FS return the last modified date with a second of precision. Thread.sleep(1500); file.setLastModified(System.currentTimeMillis()); // undeployment followed by redeployment assertWaitUntil(() -> undeploy.get() == 2 && deploy.get() == 3); }
@Test public void testOSSpecificIncludePaths() throws IOException, InterruptedException { watcher.watch(); // Initial deployment assertWaitUntil(() -> deploy.get() == 1); // create a file to be matched using windows style include pattern File winDir = new File(root, "windows"); winDir.mkdir(); Thread.sleep(500); File winFile = new File(winDir, "foo.win"); winFile.createNewFile(); // undeployment followed by redeployment assertWaitUntil(() -> undeploy.get() == 1 && deploy.get() == 2); Thread.sleep(1000); // create a file to be matched using *nix style include pattern File nixDir = new File(root, "unix"); nixDir.mkdir(); Thread.sleep(500); File nixFile = new File(nixDir, "foo.nix"); nixFile.createNewFile(); // undeployment followed by redeployment assertWaitUntil(() -> undeploy.get() == 2 && deploy.get() == 3); }
@Test public void testCaseSensitivity() throws IOException, InterruptedException { watcher.watch(); // Initial deployment assertWaitUntil(() -> deploy.get() == 1); // create a file to be matched against "FOO.bar" pattern File file = new File(root, "fOo.BAr"); file.createNewFile(); if (ExecUtils.isWindows()) { // undeployment followed by redeployment. Windows is not case sensitive assertWaitUntil(() -> undeploy.get() == 1 && deploy.get() == 2, "expected undeploy " + undeploy.get() + " == 1 and deploy " + deploy.get() + " == 2"); } else { // It depends on the file system, we can't really test anything in a reliable way. } }
@Test public void testFileAdditionAndModificationInDirectory() throws IOException, InterruptedException { watcher.watch(); // Wait until the file monitoring is set up (ugly, but I don't know any way to detect this). Thread.sleep(500); // Initial deployment assertWaitUntil(() -> deploy.get() == 1); File newDir = new File(root, "directory"); newDir.mkdir(); Thread.sleep(500); File file = new File(newDir, "foo.txt"); file.createNewFile(); // undeployment followed by redeployment assertWaitUntil(() -> undeploy.get() == 1 && deploy.get() == 2); Thread.sleep(1000); // Update file // Simulate a 'touch' file.setLastModified(System.currentTimeMillis()); // undeployment followed by redeployment assertWaitUntil(() -> undeploy.get() == 2 && deploy.get() == 3); Thread.sleep(1000); // delete directory deleteRecursive(newDir); assertWaitUntil(() -> undeploy.get() == 3 && deploy.get() == 4); }
watcher.watch(); assertWaitUntil(() -> deploy.get() == 1);
/** * Initializes the redeployment cycle. In "redeploy mode", the application is launched as background, and is * restarted after every change. A {@link Watcher} instance is responsible for monitoring files and triggering the * redeployment. */ protected synchronized void initializeRedeployment() { if (watcher != null) { throw new IllegalStateException("Redeployment already started ? The watcher already exists"); } // Compute the application id. We append "-redeploy" to ease the identification in the process list. vertxApplicationBackgroundId = UUID.randomUUID().toString() + "-redeploy"; watcher = new Watcher(getCwd(), redeploy, this::startAsBackgroundApplication, // On deploy this::stopBackgroundApplication, // On undeploy onRedeployCommand, // In between command redeployGracePeriod, // The redeploy grace period redeployScanPeriod); // The redeploy scan period // Close the watcher when the JVM is terminating. // Notice that the vert.x finalizer is not registered when we run in redeploy mode. Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { shutdownRedeployment(); } }); // Start the watching process, it triggers the initial deployment. watcher.watch(); }
@Test public void testWithANonMatchingFile() throws IOException, InterruptedException { watcher.watch(); // Initial deployment assertWaitUntil(() -> deploy.get() == 1); File file = new File(root, "foo.nope"); file.createNewFile(); Thread.sleep(500); assertThat(undeploy.get()).isEqualTo(0); assertThat(deploy.get()).isEqualTo(1); }
@Test public void testFileAddition() throws IOException { watcher.watch(); // Initial deployment assertWaitUntil(() -> deploy.get() == 1); File file = new File(root, "foo.txt"); file.createNewFile(); // undeployment followed by redeployment assertWaitUntil(() -> undeploy.get() == 1 && deploy.get() == 2); }
@Test public void testFileDeletion() throws IOException, InterruptedException { File file = new File(root, "foo.txt"); file.createNewFile(); watcher.watch(); // Initial deployment assertWaitUntil(() -> deploy.get() == 1); // Wait until the file monitoring is set up (ugly, but I don't know any way to detect this). Thread.sleep(500); file.delete(); // undeployment followed by redeployment assertWaitUntil(() -> undeploy.get() == 1 && deploy.get() == 2); }
@Test public void testFileModification() throws IOException, InterruptedException { File file = new File(root, "foo.txt"); watcher.watch(); // Initial deployment assertWaitUntil(() -> deploy.get() == 1); file.createNewFile(); assertWaitUntil(() -> deploy.get() == 2); // Simulate a 'touch', we wait more than a second to avoid being in the same second as the creation. This is because // some FS return the last modified date with a second of precision. Thread.sleep(1500); file.setLastModified(System.currentTimeMillis()); // undeployment followed by redeployment assertWaitUntil(() -> undeploy.get() == 2 && deploy.get() == 3); }
@Test public void testCaseSensitivity() throws IOException, InterruptedException { watcher.watch(); // Initial deployment assertWaitUntil(() -> deploy.get() == 1); // create a file to be matched against "FOO.bar" pattern File file = new File(root, "fOo.BAr"); file.createNewFile(); if (ExecUtils.isWindows()) { // undeployment followed by redeployment. Windows is not case sensitive assertWaitUntil(() -> undeploy.get() == 1 && deploy.get() == 2, "expected undeploy " + undeploy.get() + " == 1 and deploy " + deploy.get() + " == 2"); } else { // It depends on the file system, we can't really test anything in a reliable way. } }
@Test public void testOSSpecificIncludePaths() throws IOException, InterruptedException { watcher.watch(); // Initial deployment assertWaitUntil(() -> deploy.get() == 1); // create a file to be matched using windows style include pattern File winDir = new File(root, "windows"); winDir.mkdir(); Thread.sleep(500); File winFile = new File(winDir, "foo.win"); winFile.createNewFile(); // undeployment followed by redeployment assertWaitUntil(() -> undeploy.get() == 1 && deploy.get() == 2); Thread.sleep(1000); // create a file to be matched using *nix style include pattern File nixDir = new File(root, "unix"); nixDir.mkdir(); Thread.sleep(500); File nixFile = new File(nixDir, "foo.nix"); nixFile.createNewFile(); // undeployment followed by redeployment assertWaitUntil(() -> undeploy.get() == 2 && deploy.get() == 3); }
@Test public void testFileAdditionAndModificationInDirectory() throws IOException, InterruptedException { watcher.watch(); // Wait until the file monitoring is set up (ugly, but I don't know any way to detect this). Thread.sleep(500); // Initial deployment assertWaitUntil(() -> deploy.get() == 1); File newDir = new File(root, "directory"); newDir.mkdir(); Thread.sleep(500); File file = new File(newDir, "foo.txt"); file.createNewFile(); // undeployment followed by redeployment assertWaitUntil(() -> undeploy.get() == 1 && deploy.get() == 2); Thread.sleep(1000); // Update file // Simulate a 'touch' file.setLastModified(System.currentTimeMillis()); // undeployment followed by redeployment assertWaitUntil(() -> undeploy.get() == 2 && deploy.get() == 3); Thread.sleep(1000); // delete directory deleteRecursive(newDir); assertWaitUntil(() -> undeploy.get() == 3 && deploy.get() == 4); }
watcher.watch(); assertWaitUntil(() -> deploy.get() == 1);