]> source.dussan.org Git - gitblit.git/commitdiff
alternative variant to disable thread creation by the scheduledExecutor in test selen... 70/head
authorSHaselbauer <sarah.haselbauer@akquinet.de>
Wed, 23 Jan 2013 16:47:55 +0000 (17:47 +0100)
committerSHaselbauer <sarah.haselbauer@akquinet.de>
Wed, 23 Jan 2013 16:47:55 +0000 (17:47 +0100)
src/com/gitblit/GitBlit.java
src/com/gitblit/GitBlitServer.java
tests/de/akquinet/devops/GitBlit4UITests.java [new file with mode: 0644]
tests/de/akquinet/devops/GitBlitServer4UITests.java [new file with mode: 0644]
tests/de/akquinet/devops/GitblitRunnable.java

index f47e76cac6431bbbb53b2e9a26fe5e3e5aa1faf8..4cfd61e46638a5a31defa960d983ed2bc342b095 100644 (file)
@@ -3096,13 +3096,7 @@ public class GitBlit implements ServletContextListener {
                }\r
                \r
                // schedule lucene engine\r
-               boolean luceneIndexing = settings.getBoolean(Keys.web.allowLuceneIndexing, true);\r
-               logger.info("Lucene indexing is " + (luceneIndexing ? "" : "not") + " activated");\r
-               \r
-               if (luceneIndexing) {\r
-                       scheduledExecutor.scheduleAtFixedRate(luceneExecutor, 1, 2,  TimeUnit.MINUTES);\r
-                       logger.info("Lucene executor is scheduled to process indexed branches every 2 minutes.");      \r
-               }\r
+               enableLuceneIndexing();\r
 \r
                \r
                // schedule gc engine\r
@@ -3184,6 +3178,23 @@ public class GitBlit implements ServletContextListener {
                }\r
        }\r
        \r
+       protected void enableLuceneIndexing() {\r
+               scheduledExecutor.scheduleAtFixedRate(luceneExecutor, 1, 2,  TimeUnit.MINUTES);\r
+               logger.info("Lucene executor is scheduled to process indexed branches every 2 minutes.");\r
+       }\r
+       \r
+       protected final Logger getLogger() {\r
+               return logger;\r
+       }\r
+       \r
+       protected final ScheduledExecutorService getScheduledExecutor() {\r
+               return scheduledExecutor;\r
+       }\r
+\r
+       protected final LuceneExecutor getLuceneExecutor() {\r
+               return luceneExecutor;\r
+       }\r
+       \r
        private void logTimezone(String type, TimeZone zone) {\r
                SimpleDateFormat df = new SimpleDateFormat("z Z");\r
                df.setTimeZone(zone);\r
index feddb93f29b04f53a8d74032dcf31c597932288b..08c0d2a27ed49cd2146eb24e1523e8d3768bff17 100644 (file)
@@ -84,6 +84,8 @@ public class GitBlitServer {
        private static Logger logger;\r
 \r
        public static void main(String... args) {\r
+               GitBlitServer server = new GitBlitServer();\r
+               \r
                // filter out the baseFolder parameter\r
                List<String> filtered = new ArrayList<String>();\r
                String folder = "data";\r
@@ -108,16 +110,16 @@ public class GitBlitServer {
                try {\r
                        jc.parse(filtered.toArray(new String[filtered.size()]));\r
                        if (params.help) {\r
-                               usage(jc, null);\r
+                               server.usage(jc, null);\r
                        }\r
                } catch (ParameterException t) {\r
-                       usage(jc, t);\r
+                       server.usage(jc, t);\r
                }\r
 \r
                if (params.stop) {\r
-                       stop(params);\r
+                       server.stop(params);\r
                } else {\r
-                       start(params);\r
+                       server.start(params);\r
                }\r
        }\r
 \r
@@ -127,7 +129,7 @@ public class GitBlitServer {
         * @param jc\r
         * @param t\r
         */\r
-       private static void usage(JCommander jc, ParameterException t) {\r
+       protected final void usage(JCommander jc, ParameterException t) {\r
                System.out.println(Constants.BORDER);\r
                System.out.println(Constants.getGitBlitVersion());\r
                System.out.println(Constants.BORDER);\r
@@ -147,7 +149,7 @@ public class GitBlitServer {
        /**\r
         * Stop Gitblt GO.\r
         */\r
-       public static void stop(Params params) {\r
+       public void stop(Params params) {\r
                try {\r
                        Socket s = new Socket(InetAddress.getByName("127.0.0.1"), params.shutdownPort);\r
                        OutputStream out = s.getOutputStream();\r
@@ -165,7 +167,7 @@ public class GitBlitServer {
        /**\r
         * Start Gitblit GO.\r
         */\r
-       private static void start(Params params) {\r
+       protected final void start(Params params) {\r
                final File baseFolder = new File(Params.baseFolder).getAbsoluteFile();\r
                FileSettings settings = params.FILESETTINGS;\r
                if (!StringUtils.isEmpty(params.settingsfile)) {\r
@@ -378,7 +380,7 @@ public class GitBlitServer {
                server.setHandler(rootContext);\r
 \r
                // Setup the GitBlit context\r
-               GitBlit gitblit = GitBlit.self();\r
+               GitBlit gitblit = getGitBlitInstance();\r
                gitblit.configureContext(settings, baseFolder, true);\r
                rootContext.addEventListener(gitblit);\r
 \r
@@ -397,6 +399,10 @@ public class GitBlitServer {
                        System.exit(100);\r
                }\r
        }\r
+       \r
+       protected GitBlit getGitBlitInstance() {\r
+               return GitBlit.self();\r
+       }\r
 \r
        /**\r
         * Creates an http connector.\r
@@ -405,7 +411,7 @@ public class GitBlitServer {
         * @param port\r
         * @return an http connector\r
         */\r
-       private static Connector createConnector(boolean useNIO, int port) {\r
+       private Connector createConnector(boolean useNIO, int port) {\r
                Connector connector;\r
                if (useNIO) {\r
                        logger.info("Setting up NIO SelectChannelConnector on port " + port);\r
@@ -440,7 +446,7 @@ public class GitBlitServer {
         * @param requireClientCertificates\r
         * @return an https connector\r
         */\r
-       private static Connector createSSLConnector(String certAlias, File keyStore, File clientTrustStore,\r
+       private Connector createSSLConnector(String certAlias, File keyStore, File clientTrustStore,\r
                        String storePassword, File caRevocationList, boolean useNIO, int port, \r
                        boolean requireClientCertificates) {\r
                GitblitSslContextFactory factory = new GitblitSslContextFactory(certAlias,\r
@@ -474,7 +480,7 @@ public class GitBlitServer {
         * @param port\r
         * @return an ajp connector\r
         */\r
-       private static Connector createAJPConnector(int port) {\r
+       private Connector createAJPConnector(int port) {\r
                logger.info("Setting up AJP Connector on port " + port);\r
                Ajp13SocketConnector ajp = new Ajp13SocketConnector();\r
                ajp.setPort(port);\r
@@ -489,7 +495,7 @@ public class GitBlitServer {
         * \r
         * @return true if this is a windows machine\r
         */\r
-       private static boolean isWindows() {\r
+       private boolean isWindows() {\r
                return System.getProperty("os.name").toLowerCase().indexOf("windows") > -1;\r
        }\r
 \r
@@ -548,7 +554,7 @@ public class GitBlitServer {
         * JCommander Parameters class for GitBlitServer.\r
         */\r
        @Parameters(separators = " ")\r
-       private static class Params {\r
+       public static class Params {\r
 \r
                public static String baseFolder;\r
 \r
diff --git a/tests/de/akquinet/devops/GitBlit4UITests.java b/tests/de/akquinet/devops/GitBlit4UITests.java
new file mode 100644 (file)
index 0000000..130f2c9
--- /dev/null
@@ -0,0 +1,25 @@
+package de.akquinet.devops;
+
+import java.util.concurrent.TimeUnit;
+
+import com.gitblit.GitBlit;
+
+public class GitBlit4UITests extends GitBlit {
+
+       private boolean luceneIndexingEnabled;
+
+       public GitBlit4UITests(boolean luceneIndexingEnabled) {
+               this.luceneIndexingEnabled = luceneIndexingEnabled;
+       }
+
+       @Override
+       protected void enableLuceneIndexing() {
+               if (luceneIndexingEnabled) {
+                       getScheduledExecutor().scheduleAtFixedRate(getLuceneExecutor(), 1,
+                                       2, TimeUnit.MINUTES);
+                       getLogger()
+                                       .info("Lucene executor is scheduled to process indexed branches every 2 minutes.");
+               }
+       }
+       
+}
diff --git a/tests/de/akquinet/devops/GitBlitServer4UITests.java b/tests/de/akquinet/devops/GitBlitServer4UITests.java
new file mode 100644 (file)
index 0000000..2d54be2
--- /dev/null
@@ -0,0 +1,62 @@
+package de.akquinet.devops;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.ParameterException;
+import com.gitblit.GitBlit;
+import com.gitblit.GitBlitServer;
+
+public class GitBlitServer4UITests extends GitBlitServer {
+
+       public static void main(String... args) {
+               GitBlitServer4UITests server = new GitBlitServer4UITests();
+
+               // filter out the baseFolder parameter
+               List<String> filtered = new ArrayList<String>();
+               String folder = "data";
+               for (int i = 0; i < args.length; i++) {
+                       String arg = args[i];
+                       if (arg.equals("--baseFolder")) {
+                               if (i + 1 == args.length) {
+                                       System.out.println("Invalid --baseFolder parameter!");
+                                       System.exit(-1);
+                               } else if (args[i + 1] != ".") {
+                                       folder = args[i + 1];
+                               }
+                               i = i + 1;
+                       } else {
+                               filtered.add(arg);
+                       }
+               }
+
+               Params.baseFolder = folder;
+               Params params = new Params();
+               JCommander jc = new JCommander(params);
+               try {
+                       jc.parse(filtered.toArray(new String[filtered.size()]));
+                       if (params.help) {
+                               server.usage(jc, null);
+                       }
+               } catch (ParameterException t) {
+                       server.usage(jc, t);
+               }
+
+               if (params.stop) {
+                       server.stop(params);
+               } else {
+                       server.start(params);
+               }
+       }
+
+       private GitBlit4UITests instance;
+
+       @Override
+       protected GitBlit getGitBlitInstance() {
+               if (instance == null) {
+                       instance = new GitBlit4UITests(false);
+               }
+               return instance;
+       }
+}
index fc08f5af16b795c1cd4a6b8182f91a0dca00d706..66a31e3c11cc9896043d0c440bb58fcbc2e8f6d9 100644 (file)
@@ -70,7 +70,7 @@ public class GitblitRunnable implements Runnable {
 
                }
                try {
-                       GitBlitServer.main("--httpPort", "" + httpPort, "--httpsPort", ""
+                       GitBlitServer4UITests.main("--httpPort", "" + httpPort, "--httpsPort", ""
                                        + httpsPort, "--shutdownPort", "" + shutdownPort,
                                        "--repositoriesFolder",
                                        "\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"",