IGNITE-944: proper look up of a default log file name
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/31eb38d7 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/31eb38d7 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/31eb38d7 Branch: refs/heads/ignite-2224-2 Commit: 31eb38d72cd451f8499725a1019a837cc7a6fe0c Parents: 4edc7bd Author: Saikat Maitra <saikat.mai...@gmail.com> Authored: Wed Jan 27 13:01:41 2016 +0300 Committer: Denis Magda <dma...@gridgain.com> Committed: Wed Jan 27 13:01:41 2016 +0300 ---------------------------------------------------------------------- modules/core/pom.xml | 3 - .../handlers/log/GridLogCommandHandler.java | 16 ++---- .../handlers/log/GridLogCommandHandlerTest.java | 58 +++++++++++++++++--- 3 files changed, 55 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/31eb38d7/modules/core/pom.xml ---------------------------------------------------------------------- diff --git a/modules/core/pom.xml b/modules/core/pom.xml index bdf822b..b07a754 100644 --- a/modules/core/pom.xml +++ b/modules/core/pom.xml @@ -229,9 +229,6 @@ <exclude>**/*.java</exclude> </excludes> </testResource> - <testResource> - <directory>src/test/resources</directory> - </testResource> </testResources> <plugins> http://git-wip-us.apache.org/repos/asf/ignite/blob/31eb38d7/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/log/GridLogCommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/log/GridLogCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/log/GridLogCommandHandler.java index 4957993..603faf3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/log/GridLogCommandHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/log/GridLogCommandHandler.java @@ -18,16 +18,11 @@ package org.apache.ignite.internal.processors.rest.handlers.log; import java.io.BufferedReader; import java.io.File; -import java.io.FileInputStream; import java.io.FileReader; import java.io.IOException; -import java.net.URI; -import java.nio.charset.Charset; -import java.nio.file.Files; import java.nio.file.InvalidPathException; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Collection; + import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.IgniteInternalFuture; @@ -51,11 +46,6 @@ public class GridLogCommandHandler extends GridRestCommandHandlerAdapter { private static final Collection<GridRestCommand> SUPPORTED_COMMANDS = U.sealList(LOG); /** - * Default log file name * - */ - private static final String DEFAULT_LOG_PATH = "work/log/ignite.log"; - - /** * Default log file start line number * */ private static final int DEFAULT_FROM = 0; @@ -126,7 +116,9 @@ public class GridLogCommandHandler extends GridRestCommandHandlerAdapter { if (req0.path() != null) logFile = new File(req0.path()); else - logFile = new File(ctx.config().getIgniteHome() + "/" + DEFAULT_LOG_PATH); + logFile = new File(log.fileName() == null ? + ctx.config().getIgniteHome() + "/" + "work/log/ignite.log" : + log.fileName()); } catch (InvalidPathException e) { return new GridFinishedFuture<>(new GridRestResponse(GridRestResponse.STATUS_FAILED, http://git-wip-us.apache.org/repos/asf/ignite/blob/31eb38d7/modules/core/src/test/java/org/apache/ignite/internal/processors/rest/handlers/log/GridLogCommandHandlerTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/rest/handlers/log/GridLogCommandHandlerTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/rest/handlers/log/GridLogCommandHandlerTest.java index cc673fb..572b267 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/rest/handlers/log/GridLogCommandHandlerTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/rest/handlers/log/GridLogCommandHandlerTest.java @@ -16,7 +16,14 @@ */ package org.apache.ignite.internal.processors.rest.handlers.log; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; import java.util.Collection; +import java.util.List; + import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.processors.rest.GridRestCommand; import org.apache.ignite.internal.processors.rest.GridRestResponse; @@ -28,6 +35,45 @@ import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; * REST log command handler tests. */ public class GridLogCommandHandlerTest extends GridCommonAbstractTest { + /** */ + private String igniteHome = System.getProperty("user.dir"); + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + List<String> lines = Arrays.asList("[22:01:30,329][INFO ][grid-load-test-thread-12][GridDeploymentLocalStore] ", + "[22:01:30,329][INFO ][grid-load-test-thread-18][GridDeploymentLocalStore] Removed undeployed class: \n", + "[22:01:30,329][INFO ][grid-load-test-thread-18][GridDeploymentLocalStore] Task locally undeployed: \n" + ); + + Path file = Paths.get("test.log"); + Files.write(file, lines, Charset.forName("UTF-8")); + + lines = Arrays.asList("[22:01:30,329][INFO ][grid-load-test-thread-12][GridDeploymentLocalStore] ", + "[22:01:30,329][INFO ][grid-load-test-thread-18][GridDeploymentLocalStore] Removed undeployed class: \n", + "[22:01:30,329][INFO ][grid-load-test-thread-18][GridDeploymentLocalStore] Task locally undeployed: \n" + ); + + Path dir = Paths.get(igniteHome + "/work/log"); + Files.createDirectories(dir); + + file = Paths.get(igniteHome + "/work/log/" + "ignite.log"); + Files.write(file, lines, Charset.forName("UTF-8")); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + Path file = Paths.get("test.log"); + Files.delete(file); + + Files.delete(Paths.get(igniteHome + "/work/log/" + "ignite.log")); + Files.delete(Paths.get(igniteHome + "/work/log/")); + Files.delete(Paths.get(igniteHome + "/work/")); + + super.afterTestsStopped(); + } + /** * @throws Exception If failed. */ @@ -62,8 +108,7 @@ public class GridLogCommandHandlerTest extends GridCommonAbstractTest { req.to(5); req.from(2); - req.path(getClass().getResource("/test.log").getFile()); - + req.path("test.log"); IgniteInternalFuture<GridRestResponse> resp = cmdHandler.handleAsync(req); assertNull(resp.result().getError()); @@ -78,7 +123,7 @@ public class GridLogCommandHandlerTest extends GridCommonAbstractTest { GridLogCommandHandler cmdHandler = new GridLogCommandHandler(newContext()); GridRestLogRequest req = new GridRestLogRequest(); - req.path(getClass().getResource("/test.log").getFile()); + req.path("test.log"); IgniteInternalFuture<GridRestResponse> resp = cmdHandler.handleAsync(req); @@ -92,7 +137,7 @@ public class GridLogCommandHandlerTest extends GridCommonAbstractTest { */ public void testHandleAsyncPathNotSet() throws Exception { GridTestKernalContext ctx = newContext(); - ctx.config().setIgniteHome(getClass().getResource("/").getFile()); + ctx.config().setIgniteHome(igniteHome); GridLogCommandHandler cmdHandler = new GridLogCommandHandler(ctx); GridRestLogRequest req = new GridRestLogRequest(); @@ -116,8 +161,7 @@ public class GridLogCommandHandlerTest extends GridCommonAbstractTest { req.to(2); req.from(5); - req.path(getClass().getResource("/test.log").getFile()); - + req.path("test.log"); IgniteInternalFuture<GridRestResponse> resp = cmdHandler.handleAsync(req); @@ -135,7 +179,7 @@ public class GridLogCommandHandlerTest extends GridCommonAbstractTest { req.to(2); req.from(2); - req.path(getClass().getResource("/test.log").getFile()); + req.path("test.log"); IgniteInternalFuture<GridRestResponse> resp = cmdHandler.handleAsync(req);