forked from eclipse-jkube/jkube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix eclipse-jkube#364: jkube.watch.postExec property/parameter/config…
…uration is ignored Added support for copying changed files and executing a command provided in postExec option after copying files to the application pod.
- Loading branch information
1 parent
e36a9b0
commit 59fa718
Showing
11 changed files
with
433 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...ice/docker/src/test/java/org/eclipse/jkube/kit/build/service/docker/WatchServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.kit.build.service.docker; | ||
|
||
import mockit.Mocked; | ||
import org.eclipse.jkube.kit.common.KitLogger; | ||
import org.eclipse.jkube.kit.config.image.ImageConfiguration; | ||
import org.eclipse.jkube.kit.config.image.WatchImageConfiguration; | ||
import org.eclipse.jkube.kit.config.image.WatchMode; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class WatchServiceTest { | ||
@Mocked | ||
ArchiveService archiveService; | ||
|
||
@Mocked | ||
BuildService buildService; | ||
|
||
@Mocked | ||
QueryService queryService; | ||
|
||
@Mocked | ||
RunService runService; | ||
|
||
@Mocked | ||
KitLogger logger; | ||
|
||
ImageConfiguration imageConfiguration; | ||
|
||
@Before | ||
public void setUp() { | ||
imageConfiguration = ImageConfiguration.builder() | ||
.name("test-app") | ||
.watch(WatchImageConfiguration.builder() | ||
.postExec("ls -lt /deployments") | ||
.build()) | ||
.build(); | ||
} | ||
|
||
@Test | ||
public void testCopyFilesToContainer() throws IOException { | ||
// Given | ||
AtomicBoolean fileCopied = new AtomicBoolean(false); | ||
WatchService.WatchContext watchContext = WatchService.WatchContext.builder() | ||
.watchMode(WatchMode.copy) | ||
// Override Copy task to set this value to goal executed | ||
.containerCopyTask(f -> fileCopied.compareAndSet(false,true)) | ||
.build(); | ||
File fileToCopy = Files.createTempFile("test-changed-files", "tar").toFile(); | ||
WatchService.ImageWatcher imageWatcher = new WatchService.ImageWatcher(imageConfiguration, watchContext, "test-img", "efe1234"); | ||
WatchService watchService = new WatchService(archiveService, buildService, queryService, runService, logger); | ||
|
||
// When | ||
watchService.copyFilesToContainer(fileToCopy, imageWatcher); | ||
|
||
// Then | ||
assertTrue(fileCopied.get()); | ||
} | ||
|
||
@Test | ||
public void testCallPostExec() throws Exception { | ||
// Given | ||
AtomicBoolean postExecCommandExecuted = new AtomicBoolean(false); | ||
WatchService.WatchContext watchContext = WatchService.WatchContext.builder() | ||
.watchMode(WatchMode.copy) | ||
// Override PostExec task to set this value to goal executed | ||
.containerCommandExecutor(imageWatcher -> { | ||
postExecCommandExecuted.set(true); | ||
return "Some Output"; | ||
}) | ||
.build(); | ||
WatchService.ImageWatcher imageWatcher = new WatchService.ImageWatcher(imageConfiguration, watchContext, "test-img", "efe1234"); | ||
WatchService watchService = new WatchService(archiveService, buildService, queryService, runService, logger); | ||
|
||
// When | ||
String output = watchService.callPostExec(imageWatcher); | ||
|
||
// Then | ||
assertTrue(postExecCommandExecuted.get()); | ||
assertEquals("Some Output", output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/util/TimeUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.kit.common.util; | ||
|
||
import org.eclipse.jkube.kit.common.TimeUtil; | ||
import org.junit.Test; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
public class TimeUtilTest { | ||
@Test | ||
public void testWaitUntilCondition() { | ||
long timeBeforeWait = System.currentTimeMillis(); | ||
AtomicBoolean value = new AtomicBoolean(false); | ||
new Thread(() -> value.set(true)).start(); | ||
|
||
TimeUtil.waitUntilCondition(value::get, 200); | ||
long timeAfterWait = System.currentTimeMillis(); | ||
assertTrue(timeAfterWait - timeBeforeWait < 200); | ||
} | ||
} |
Oops, something went wrong.