enable copyFileToContainer feature during container startup#742
Conversation
259e12d to
b82cbab
Compare
kiview
left a comment
There was a problem hiding this comment.
Can you please add some test cases as well?
| if (!isRunning()) { | ||
| throw new IllegalStateException("copyFileToContainer can only be used while the Container is running"); | ||
| if (!isRunning() && !isCreated()) { | ||
| throw new IllegalStateException("opyFileToContainer can only be used with created / running container"); |
| * @param mountableFile a Mountable file with path of source file / folder on host machine | ||
| * @param containerPath a destination path on conatiner to which the files / folders to be copied | ||
| */ | ||
| void addCopyFileToContainer(MountableFile mountableFile, String containerPath); |
There was a problem hiding this comment.
We've decided to deprecate the non-fluent setters, so you can omit this method.
|
|
||
|
|
||
| @Override | ||
| public void addCopyFileToContainer(MountableFile mountableFile, String containerPath) { |
There was a problem hiding this comment.
See above, you can remove this method.
a12aeae to
5ea4c94
Compare
| @@ -0,0 +1 @@ | |||
| The contents of this folder is a workaround for issues described here: https://github.com/KostyaSha/docker-java-shade/issues/1 No newline at end of file | |||
There was a problem hiding this comment.
this file (as well as other /out files) should not be commited
5ea4c94 to
0b78a2e
Compare
rnorth
left a comment
There was a problem hiding this comment.
A few minor comments from me, but this looks like a good change to be making - thank you very much!
|
|
||
| try { | ||
| Boolean created = getCurrentContainerInfo().getState().getStatus().equalsIgnoreCase("Created"); | ||
| return Boolean.TRUE.equals(created); |
There was a problem hiding this comment.
In the isRunning method the result of getRunning() is a nullable Boolean, which is why we do the TRUE.equals call in that method.
Here, equalsIgnoreCase just returns a primitive boolean, and further, getStatus() may return null.
As such, I think it would actually be safer to just replace these two lines with:
return "created".equalsIgnoreCase(getCurrentContainerInfo().getState().getStatus());
Please could we do that instead?
There was a problem hiding this comment.
Also, this method will return false if the container is not just created but also started
|
|
||
| Assert.assertTrue(filesList.contains(fileName)); | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); |
There was a problem hiding this comment.
Please let the exception be thrown from the test method, as it could be important.
|
|
||
| @Before | ||
| public void before() { | ||
| container = new GenericContainer("couchbase:latest") |
There was a problem hiding this comment.
I think we can get away with using a smaller image here (and save some startup time). Would an alpine image be OK?
There was a problem hiding this comment.
we need container to be up and running to perform this test. Alpine container is exiting immediately after start. Because of this, i am unable to use alpine container
There was a problem hiding this comment.
Use the alpine image and provide a long running command (like sleep), using withCommand() on the container.
|
|
||
| @Test | ||
| public void checkFileCopied() { | ||
| container.start(); |
There was a problem hiding this comment.
Do we need to split the instantiation/start of the container like this, or could the container just be a field with an @Rule annotation for this test? I think I'd prefer the latter, as it's the more idiomatic way.
There was a problem hiding this comment.
actually, didn't we agree to use try-with-resources style? Otherwise, if you have 5 rules in your test and run a single test all of them will start - that sucks :(
There was a problem hiding this comment.
Maybe it depends? This class has only one test method (and would have only one Rule), which is why I suggested this way. I'm very relaxed about it though; try-with-resources would also be fine.
There was a problem hiding this comment.
What is this try-with-resources? could you please provide a reference to understand this
There was a problem hiding this comment.
Sure, see here:
0b78a2e to
871f47c
Compare
| try( | ||
| GenericContainer container = new GenericContainer("alpine:latest") | ||
| .withCommand("sleep","3000") | ||
| .withCopyFileToContainer(MountableFile.forHostPath(folderPath), containerPath) |
There was a problem hiding this comment.
please use MountableFile.forClasspathResource("/mappable-resource/test-resource.txt")
871f47c to
15ebab0
Compare
| <OnMatch>DENY</OnMatch> | ||
| </turboFilter> | ||
| </configuration> No newline at end of file | ||
| </configuration> |
There was a problem hiding this comment.
This is of course an unnecessary change, but rest LGTM.
|
@rnorth Have your remarks been addressed? |
|
@rnorth Please verify whether the changes are done as requested by you and share your view in merging this branch |
|
@dharanikesav sorry for taking so long for the review! Richard is a bit busy, so I took an action to merge it :) Thanks for your contribution! A really good one! 👍 |
Currently, testcontainer is capable of copying files only after starting a container. But, we have a requirement to copy files to container after creation and then start the container. This code change is to enable copy files to container immediately after creation.