http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd28003b/modules/core/src/test/java/org/gridgain/jvmtest/ReadWriteLockMultiThreadedTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/jvmtest/ReadWriteLockMultiThreadedTest.java b/modules/core/src/test/java/org/gridgain/jvmtest/ReadWriteLockMultiThreadedTest.java deleted file mode 100644 index 556c7e6..0000000 --- a/modules/core/src/test/java/org/gridgain/jvmtest/ReadWriteLockMultiThreadedTest.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.jvmtest; - -import junit.framework.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.internal.util.typedef.*; -import org.gridgain.testframework.*; -import org.jetbrains.annotations.*; - -import java.util.concurrent.*; -import java.util.concurrent.locks.*; - -/** - * JDK read write lock test. - */ -public class ReadWriteLockMultiThreadedTest extends TestCase { - /** - * @throws Exception If failed. - */ - @SuppressWarnings({"LockAcquiredButNotSafelyReleased"}) - public void testReadThenWriteLockAcquire() throws Exception { - ReadWriteLock lock = new ReentrantReadWriteLock(); - - lock.readLock().lock(); - - lock.writeLock().lock(); - } - - /** - * - */ - public void testNotOwnedLockRelease() { - ReadWriteLock lock = new ReentrantReadWriteLock(); - - lock.readLock().unlock(); - } - - /** - * @throws Exception If failed. - */ - @SuppressWarnings({"LockAcquiredButNotSafelyReleased"}) - public void testWriteLockAcquire() throws Exception { - final ReadWriteLock lock = new ReentrantReadWriteLock(); - - lock.readLock().lock(); - - X.println("Read lock acquired."); - - IgniteFuture fut1 = GridTestUtils.runMultiThreadedAsync( - new Callable<Object>() { - @Nullable @Override public Object call() throws Exception { - X.println("Attempting to acquire write lock: " + lock); - - lock.writeLock().lock(); - - try { - X.println("Write lock acquired: " + lock); - - return null; - } - finally { - lock.writeLock().unlock(); - } - } - }, - 1, - "write-lock" - ); - - Thread.sleep(2000); - - IgniteFuture fut2 = GridTestUtils.runMultiThreadedAsync( - new Callable<Object>() { - @Nullable @Override public Object call() throws Exception { - X.println("Attempting to acquire read lock: " + lock); - - lock.readLock().lock(); - - try { - X.println("Read lock acquired: " + lock); - - return null; - } - finally { - lock.readLock().unlock(); - } - } - }, - 1, - "read-lock" - ); - - Thread.sleep(2000); - - X.println(">>> Dump threads now! <<<"); - - Thread.sleep(15 * 1000); - - X.println("Read lock released: " + lock); - - lock.readLock().unlock(); - - fut1.get(); - fut2.get(); - } - - /** - * @throws Exception If failed. - */ - @SuppressWarnings({"LockAcquiredButNotSafelyReleased"}) - public void testReadLockAcquire() throws Exception { - final ReadWriteLock lock = new ReentrantReadWriteLock(); - - lock.writeLock().lock(); - - X.println("Write lock acquired: " + lock); - - IgniteFuture fut = GridTestUtils.runMultiThreadedAsync( - new Callable<Object>() { - @Nullable @Override public Object call() throws Exception { - X.println("Attempting to acquire read lock: " + lock); - - lock.readLock().lock(); - - try { - X.println("Read lock acquired: " + lock); - - return null; - } - finally { - lock.readLock().unlock(); - } - } - }, - 1, - "read-lock" - ); - - Thread.sleep(2000); - - X.println(">>> Dump threads now! <<<"); - - Thread.sleep(15 * 1000); - - X.println("Write lock released."); - - lock.writeLock().unlock(); - - fut.get(); - } - - /** - * @throws Exception If failed. - */ - @SuppressWarnings({"LockAcquiredButNotSafelyReleased"}) - public void testTryWriteLock() throws Exception { - final ReadWriteLock lock = new ReentrantReadWriteLock(); - - lock.readLock().lock(); - - X.println("Read lock acquired."); - - IgniteFuture fut = GridTestUtils.runMultiThreadedAsync( - new Callable<Object>() { - @Nullable @Override public Object call() throws Exception { - boolean res = lock.writeLock().tryLock(); - - X.println("Attempting to try write lock: " + res); - - try { - return null; - } - finally { - if (res) - lock.writeLock().unlock(); - } - } - }, - 1, - "write-lock" - ); - - Thread.sleep(2000); - - X.println("Read lock released: " + lock); - - lock.readLock().unlock(); - - fut.get(); - } -}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd28003b/modules/core/src/test/java/org/gridgain/jvmtest/RegExpTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/jvmtest/RegExpTest.java b/modules/core/src/test/java/org/gridgain/jvmtest/RegExpTest.java deleted file mode 100644 index ae7fcc8..0000000 --- a/modules/core/src/test/java/org/gridgain/jvmtest/RegExpTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.jvmtest; - -import junit.framework.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; - -import java.util.regex.*; - -/** - * Java reg exp test. - */ -public class RegExpTest extends TestCase { - /** - * @throws Exception If failed. - */ - public void testRegExp() throws Exception { - String normal = - "swap-spaces/space1/b53b3a3d6ab90ce0268229151c9bde11|b53b3a3d6ab90ce0268229151c9bde11|1315392441288"; - - byte[] b1 = new byte[200]; - byte[] b2 = normal.getBytes(); - - U.arrayCopy(b2, 0, b1, 30, b2.length); - - CharSequence corrupt = new String(b1); - - String ptrn = "[a-z0-9/\\-]+\\|[a-f0-9]+\\|[0-9]+"; - - Pattern p = Pattern.compile(ptrn); - - Matcher matcher = p.matcher(corrupt); - - assert matcher.find(); - - X.println(String.valueOf(matcher.start())); - - assert normal.matches(ptrn); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd28003b/modules/core/src/test/java/org/gridgain/jvmtest/ServerSocketMultiThreadedTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/jvmtest/ServerSocketMultiThreadedTest.java b/modules/core/src/test/java/org/gridgain/jvmtest/ServerSocketMultiThreadedTest.java deleted file mode 100644 index e60a402..0000000 --- a/modules/core/src/test/java/org/gridgain/jvmtest/ServerSocketMultiThreadedTest.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.jvmtest; - -import junit.framework.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.gridgain.testframework.*; -import org.jetbrains.annotations.*; - -import java.net.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; - -/** - * Java server socket test. - * <p> - * http://gridgain.jira.com/browse/GG-2068 - * <p> - * When binding server socket to the same port in multiple threads, either - * BindException or SocketException may be thrown. Purpose of this test is - * to find some explanation to that. - */ -public class ServerSocketMultiThreadedTest extends TestCase { - /** */ - private static final int THREADS_CNT = 10; - - /** */ - private static final int ITER_CNT = 10000; - - /** - * @throws Exception If failed. - */ - public void testConcurrentBind() throws Exception { - final AtomicInteger bindExCnt = new AtomicInteger(); - final AtomicInteger sockExCnt = new AtomicInteger(); - final AtomicInteger okCnt = new AtomicInteger(); - - final CyclicBarrier finishBarrier = new CyclicBarrier( - THREADS_CNT, - new Runnable() { - private int i; - - @Override public void run() { - if (++i % 250 == 0) - X.println("Finished iteration [threadName=" + Thread.currentThread().getName() + - ", iter=" + i + ']'); - } - }); - - final InetAddress addr = InetAddress.getByName("127.0.0.1"); - - GridTestUtils.runMultiThreaded( - new Callable<Object>() { - @Nullable @Override public Object call() throws Exception { - ServerSocket srvSock = null; - - for (int i = 0; i < ITER_CNT; i++) { - try { - srvSock = new ServerSocket(60000, 0, addr); - - okCnt.incrementAndGet(); - } - catch (BindException ignore) { - bindExCnt.incrementAndGet(); - } - catch (SocketException ignore) { - sockExCnt.incrementAndGet(); - } - finally { - finishBarrier.await(); - - U.closeQuiet(srvSock); - } - } - - return null; - } - }, - THREADS_CNT, - "binder" - ); - - X.println("Test stats [bindExCnt=" + bindExCnt.get() + ", sockExCnt=" + sockExCnt.get() + - ", okCnt=" + okCnt + ']'); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd28003b/modules/core/src/test/java/org/gridgain/startup/GridRandomCommandLineLoader.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/startup/GridRandomCommandLineLoader.java b/modules/core/src/test/java/org/gridgain/startup/GridRandomCommandLineLoader.java deleted file mode 100644 index ac477f6..0000000 --- a/modules/core/src/test/java/org/gridgain/startup/GridRandomCommandLineLoader.java +++ /dev/null @@ -1,400 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.startup; - -import org.apache.commons.cli.*; -import org.apache.ignite.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.lifecycle.*; -import org.apache.log4j.*; -import org.apache.log4j.varia.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.gridgain.testframework.*; -import org.gridgain.testframework.junits.logger.*; -import org.jetbrains.annotations.*; -import org.springframework.beans.*; -import org.springframework.context.*; -import org.springframework.context.support.*; - -import java.io.*; -import java.net.*; -import java.util.*; -import java.util.concurrent.*; - -import static org.apache.ignite.IgniteState.*; - -/** - * This class defines random command-line GridGain loader. This loader can be used - * to randomly start and stop GridGain from command line for tests. This loader is a Java - * application with {@link #main(String[])} method that accepts command line arguments. - * See below for details. - */ -public final class GridRandomCommandLineLoader { - /** Name of the system property defining name of command line program. */ - private static final String GRIDGAIN_PROG_NAME = "GRIDGAIN_PROG_NAME"; - - /** Copyright text. Ant processed. */ - private static final String COPYRIGHT = "Copyright (C) 2014 GridGain Systems."; - - /** Version. Ant processed. */ - private static final String VER = "x.x.x"; - - /** */ - private static final String OPTION_HELP = "help"; - - /** */ - private static final String OPTION_CFG = "cfg"; - - /** */ - private static final String OPTION_MIN_TTL = "minTtl"; - - /** */ - private static final String OPTION_MAX_TTL = "maxTtl"; - - /** */ - private static final String OPTION_DURATION = "duration"; - - /** */ - private static final String OPTION_LOG_CFG = "logCfg"; - - /** Minimal value for timeout in milliseconds. */ - private static final long DFLT_MIN_TIMEOUT = 1000; - - /** Maximum value for timeout in milliseconds. */ - private static final long DFLT_MAX_TIMEOUT = 1000 * 20; - - /** Work timeout in milliseconds. */ - private static final long DFLT_RUN_TIMEOUT = 1000 * 60 * 5; - - /** Latch. */ - private static CountDownLatch latch; - - /** - * Enforces singleton. - */ - private GridRandomCommandLineLoader() { - // No-op. - } - - /** - * Echos the given messages. - * - * @param msg Message to echo. - */ - private static void echo(String msg) { - assert msg != null; - - System.out.println(msg); - } - - /** - * Echos exception stack trace. - * - * @param e Exception to print. - */ - private static void echo(IgniteCheckedException e) { - assert e != null; - - System.err.println(e); - } - - /** - * Exists with optional error message, usage show and exit code. - * - * @param errMsg Optional error message. - * @param options Command line options to show usage information. - * @param exitCode Exit code. - */ - private static void exit(@Nullable String errMsg, @Nullable Options options, int exitCode) { - if (errMsg != null) - echo("ERROR: " + errMsg); - - String runner = System.getProperty(GRIDGAIN_PROG_NAME, "randggstart.{sh|bat}"); - - int space = runner.indexOf(' '); - - runner = runner.substring(0, space == -1 ? runner.length() : space); - - if (options != null) { - HelpFormatter formatter = new HelpFormatter(); - - formatter.printHelp(runner, options); - } - - System.exit(exitCode); - } - - /** - * Prints logo. - */ - private static void logo() { - echo("GridGain Random Command Line Loader, ver. " + VER); - echo(COPYRIGHT); - echo(""); - } - - /** - * Main entry point. - * - * @param args Command line arguments. - */ - @SuppressWarnings({"BusyWait"}) - public static void main(String[] args) { - System.setProperty(IgniteSystemProperties.GG_UPDATE_NOTIFIER, "false"); - - logo(); - - Options options = createOptions(); - - // Create the command line parser. - CommandLineParser parser = new PosixParser(); - - String cfgPath = null; - - long minTtl = DFLT_MIN_TIMEOUT; - long maxTtl = DFLT_MAX_TIMEOUT; - long duration = DFLT_RUN_TIMEOUT; - - String logCfgPath = null; - - try { - CommandLine cmd = parser.parse(options, args); - - if (cmd.hasOption(OPTION_HELP)) - exit(null, options, 0); - - if (!cmd.hasOption(OPTION_LOG_CFG)) - exit("-log should be set", options, -1); - else - logCfgPath = cmd.getOptionValue(OPTION_LOG_CFG); - - if (cmd.hasOption(OPTION_CFG)) - cfgPath = cmd.getOptionValue(OPTION_CFG); - - try { - if (cmd.hasOption(OPTION_DURATION)) - duration = Long.parseLong(cmd.getOptionValue(OPTION_DURATION)); - } - catch (NumberFormatException ignored) { - exit("Invalid argument for option: " + OPTION_DURATION, options, -1); - } - - try { - if (cmd.hasOption(OPTION_MIN_TTL)) - minTtl = Long.parseLong(cmd.getOptionValue(OPTION_MIN_TTL)); - } - catch (NumberFormatException ignored) { - exit("Invalid argument for option: " + OPTION_MIN_TTL, options, -1); - } - - try { - if (cmd.hasOption(OPTION_MAX_TTL)) - maxTtl = Long.parseLong(cmd.getOptionValue(OPTION_MAX_TTL)); - } - catch (NumberFormatException ignored) { - exit("Invalid argument for option: " + OPTION_MAX_TTL, options, -1); - } - - if (minTtl >= maxTtl) - exit("Invalid arguments for options: " + OPTION_MAX_TTL + ", " + OPTION_MIN_TTL, options, -1); - } - catch (ParseException e) { - exit(e.getMessage(), options, -1); - } - - System.out.println("Configuration path: " + cfgPath); - System.out.println("Log4j configuration path: " + logCfgPath); - System.out.println("Duration: " + duration); - System.out.println("Minimum TTL: " + minTtl); - System.out.println("Maximum TTL: " + maxTtl); - - G.addListener(new IgniteListener() { - @Override public void onStateChange(String name, IgniteState state) { - if (state == STOPPED && latch != null) - latch.countDown(); - } - }); - - Random rand = new Random(); - - long now = System.currentTimeMillis(); - - long end = duration + System.currentTimeMillis(); - - try { - while (now < end) { - G.start(getConfiguration(cfgPath, logCfgPath)); - - long delay = rand.nextInt((int)(maxTtl - minTtl)) + minTtl; - - delay = (now + delay > end) ? (end - now) : delay; - - now = System.currentTimeMillis(); - - echo("Time left (ms): " + (end - now)); - - echo("Going to sleep for (ms): " + delay); - - Thread.sleep(delay); - - G.stopAll(false); - - now = System.currentTimeMillis(); - } - } - catch (IgniteCheckedException e) { - echo(e); - - exit("Failed to start grid: " + e.getMessage(), null, -1); - } - catch (InterruptedException e) { - echo("Loader was interrupted (exiting): " + e.getMessage()); - } - - latch = new CountDownLatch(G.allGrids().size()); - - try { - while (latch.getCount() > 0) - latch.await(); - } - catch (InterruptedException e) { - echo("Loader was interrupted (exiting): " + e.getMessage()); - } - - System.exit(0); - } - - /** - * Initializes configurations. - * - * @param springCfgPath Configuration file path. - * @param logCfgPath Log file name. - * @return List of configurations. - * @throws IgniteCheckedException If an error occurs. - */ - @SuppressWarnings("unchecked") - private static IgniteConfiguration getConfiguration(String springCfgPath, @Nullable String logCfgPath) - throws IgniteCheckedException { - assert springCfgPath != null; - - File path = GridTestUtils.resolveGridGainPath(springCfgPath); - - if (path == null) - throw new IgniteCheckedException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + - ". Note that this path should be either absolute path or a relative path to GRIDGAIN_HOME."); - - if (!path.isFile()) - throw new IgniteCheckedException("Provided file path is not a file: " + path); - - // Add no-op logger to remove no-appender warning. - Appender app = new NullAppender(); - - Logger.getRootLogger().addAppender(app); - - ApplicationContext springCtx; - - try { - springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString()); - } - catch (BeansException | MalformedURLException e) { - throw new IgniteCheckedException("Failed to instantiate Spring XML application context: " + e.getMessage(), e); - } - - Map cfgMap; - - try { - // Note: Spring is not generics-friendly. - cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class); - } - catch (BeansException e) { - throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + - e.getMessage() + ']', e); - } - - if (cfgMap == null) - throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path); - - // Remove previously added no-op logger. - Logger.getRootLogger().removeAppender(app); - - if (cfgMap.size() != 1) - throw new IgniteCheckedException("Spring configuration file should contain exactly 1 grid configuration: " + path); - - IgniteConfiguration cfg = (IgniteConfiguration)F.first(cfgMap.values()); - - assert cfg != null; - - if (logCfgPath != null) - cfg.setGridLogger(new GridTestLog4jLogger(U.resolveGridGainUrl(logCfgPath))); - - return cfg; - } - - /** - * Creates cli options. - * - * @return Command line options - */ - private static Options createOptions() { - Options options = new Options(); - - Option help = new Option(OPTION_HELP, "print this message"); - - Option cfg = new Option(null, OPTION_CFG, true, "path to Spring XML configuration file."); - - cfg.setValueSeparator('='); - cfg.setType(String.class); - - Option minTtl = new Option(null, OPTION_MIN_TTL, true, "node minimum time to live."); - - minTtl.setValueSeparator('='); - minTtl.setType(Long.class); - - Option maxTtl = new Option(null, OPTION_MAX_TTL, true, "node maximum time to live."); - - maxTtl.setValueSeparator('='); - maxTtl.setType(Long.class); - - Option duration = new Option(null, OPTION_DURATION, true, "run timeout."); - - duration.setValueSeparator('='); - duration.setType(Long.class); - - Option log = new Option(null, OPTION_LOG_CFG, true, "path to log4j configuration file."); - - log.setValueSeparator('='); - log.setType(String.class); - - options.addOption(help); - - OptionGroup grp = new OptionGroup(); - - grp.setRequired(true); - - grp.addOption(cfg); - grp.addOption(minTtl); - grp.addOption(maxTtl); - grp.addOption(duration); - grp.addOption(log); - - options.addOptionGroup(grp); - - return options; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd28003b/modules/core/src/test/java/org/gridgain/startup/GridVmNodesStarter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/startup/GridVmNodesStarter.java b/modules/core/src/test/java/org/gridgain/startup/GridVmNodesStarter.java deleted file mode 100644 index 05ee75c..0000000 --- a/modules/core/src/test/java/org/gridgain/startup/GridVmNodesStarter.java +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.startup; - -import org.apache.commons.cli.*; -import org.apache.ignite.*; -import org.apache.ignite.configuration.*; -import org.apache.log4j.*; -import org.apache.log4j.varia.*; -import org.apache.ignite.internal.util.typedef.*; -import org.gridgain.testframework.*; -import org.springframework.beans.*; -import org.springframework.context.*; -import org.springframework.context.support.*; - -import java.io.*; -import java.net.*; -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; - -import static org.apache.ignite.IgniteSystemProperties.*; - -/** - * This class - * - */ -public final class GridVmNodesStarter { - /** Name of the system property defining name of command line program. */ - private static final String GRIDGAIN_PROG_NAME = "GRIDGAIN_PROG_NAME"; - - /** */ - private static final String GRID_NAME_PREF = "gg-vm-grid-"; - - /** */ - private static final int DFLT_NODES_COUNT = 20; - - /** */ - private static final String OPTION_CFG = "cfg"; - - /** */ - private static final String OPTION_N = "n"; - - /** */ - private static final AtomicInteger gridCnt = new AtomicInteger(); - - /** - * Enforces singleton. - */ - private GridVmNodesStarter() { - // No-op. - } - - /** - * Echos the given messages. - * - * @param msg Message to echo. - */ - private static void echo(String msg) { - assert msg != null; - - System.out.println(msg); - } - - /** - * Echos exception stack trace. - * - * @param e Exception to print. - */ - private static void echo(IgniteCheckedException e) { - assert e != null; - - System.err.println(e); - } - - /** - * Exists with optional error message, usage show and exit code. - * - * @param errMsg Optional error message. - * @param options Command line options to show usage information. - * @param exitCode Exit code. - */ - private static void exit(String errMsg, Options options, int exitCode) { - if (errMsg != null) - echo("ERROR: " + errMsg); - - String runner = System.getProperty(GRIDGAIN_PROG_NAME, "randggstart.{sh|bat}"); - - int space = runner.indexOf(' '); - - runner = runner.substring(0, space == -1 ? runner.length() : space); - - if (options != null) { - HelpFormatter formatter = new HelpFormatter(); - - formatter.printHelp(runner, options); - } - - System.exit(exitCode); - } - - /** - * Main entry point. - * - * @param args Command line arguments. - * @throws IgniteCheckedException If failed. - */ - public static void main(String[] args) throws IgniteCheckedException { - System.setProperty(GG_UPDATE_NOTIFIER, "false"); - - Options options = createOptions(); - - // Create the command line parser. - CommandLineParser parser = new PosixParser(); - - String cfgPath = null; - - Integer nodesCnt = null; - - try { - CommandLine cmd = parser.parse(options, args); - - if (cmd.hasOption(OPTION_CFG)) - cfgPath = cmd.getOptionValue(OPTION_CFG); - - if (cmd.hasOption(OPTION_N)) - try { - nodesCnt = Integer.parseInt(cmd.getOptionValue(OPTION_N)); - } - catch (NumberFormatException ignored) { - // No-op. - } - - if (nodesCnt == null) - nodesCnt = DFLT_NODES_COUNT; - } - catch (ParseException e) { - exit(e.getMessage(), options, -1); - } - - System.out.println(); - System.out.println(">>> VM Nodes Starter parameters:"); - System.out.println(" Nodes Count: " + nodesCnt); - System.out.println(" Config Path: " + cfgPath); - System.out.println(); - - final IgniteConfiguration[] cfgs = new IgniteConfiguration[nodesCnt]; - - for (int i = 0; i < nodesCnt; i++) - cfgs[i] = getConfigurations(cfgPath).iterator().next(); - - final AtomicInteger cfgIdx = new AtomicInteger(0); - - GridTestUtils.runMultiThreadedAsync(new Callable<Object>() { - @Override public Object call() throws Exception { - G.start(cfgs[cfgIdx.getAndIncrement()]); - - return null; - } - }, nodesCnt, "test-node-starter"); - } - - /** - * Initializes configurations. - * - * - * @param springCfgPath Configuration file path. - * @return List of configurations. - * @throws IgniteCheckedException If an error occurs. - */ - @SuppressWarnings("unchecked") - private static Iterable<IgniteConfiguration> getConfigurations(String springCfgPath) - throws IgniteCheckedException { - File path = GridTestUtils.resolveGridGainPath(springCfgPath); - - if (path == null) - throw new IgniteCheckedException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + - ". Note that this path should be either absolute path or a relative path to GRIDGAIN_HOME."); - - if (!path.isFile()) - throw new IgniteCheckedException("Provided file path is not a file: " + path); - - // Add no-op logger to remove no-appender warning. - Appender app = new NullAppender(); - - Logger.getRootLogger().addAppender(app); - - ApplicationContext springCtx; - - try { - springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString()); - } - catch (BeansException | MalformedURLException e) { - throw new IgniteCheckedException("Failed to instantiate Spring XML application context: " + e.getMessage(), e); - } - - Map cfgMap; - - try { - // Note: Spring is not generics-friendly. - cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class); - } - catch (BeansException e) { - throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + - e.getMessage() + ']', e); - } - - if (cfgMap == null) - throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path); - - // Remove previously added no-op logger. - Logger.getRootLogger().removeAppender(app); - - if (cfgMap.isEmpty()) - throw new IgniteCheckedException("Can't find grid factory configuration in: " + path); - - Collection<IgniteConfiguration> res = new ArrayList<>(); - - for (IgniteConfiguration cfg : (Collection<IgniteConfiguration>)cfgMap.values()) { - res.add(cfg); - - cfg.setGridName(GRID_NAME_PREF + gridCnt.incrementAndGet()); - } - - return res; - } - - /** - * Creates cli options. - * - * @return Command line options - */ - private static Options createOptions() { - Options options = new Options(); - - OptionGroup grp = new OptionGroup(); - - grp.setRequired(true); - - Option cfg = new Option(OPTION_CFG, null, true, "path to Spring XML configuration file."); - - cfg.setArgName("file"); - - Option n = new Option(null, OPTION_N, true, "nodes count."); - - n.setValueSeparator('='); - n.setType(Integer.class); - - grp.addOption(cfg); - grp.addOption(n); - - options.addOptionGroup(grp); - - return options; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd28003b/modules/core/src/test/java/org/gridgain/startup/package.html ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/startup/package.html b/modules/core/src/test/java/org/gridgain/startup/package.html deleted file mode 100644 index 1f85ff2..0000000 --- a/modules/core/src/test/java/org/gridgain/startup/package.html +++ /dev/null @@ -1,23 +0,0 @@ -<!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> -<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> -<html> -<body> - <!-- Package description. --> - Contains internal tests or test related classes and interfaces. -</body> -</html> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd28003b/modules/core/src/test/java/org/gridgain/testframework/GridFileLock.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/testframework/GridFileLock.java b/modules/core/src/test/java/org/gridgain/testframework/GridFileLock.java deleted file mode 100644 index dbc38a9..0000000 --- a/modules/core/src/test/java/org/gridgain/testframework/GridFileLock.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.testframework; - -import org.apache.ignite.*; -import org.apache.ignite.internal.util.typedef.internal.*; - -import java.io.*; -import java.nio.channels.*; - -/** - * OS-level file lock implementation. - */ -public class GridFileLock { - /** FS file for lock. */ - private final File file; - - /** Random access file for FS file. */ - private final RandomAccessFile raFile; - - /** File lock. */ - private FileLock fileLock; - - /** - * Initializes the lock. - * - * The constructor opens the lock file, which then should be - * closed with {@link #close()} method. - * - * @param file FS file to use as a lock file. - * @throws FileNotFoundException If error occurs on opening or creating the file. - */ - GridFileLock(File file) throws FileNotFoundException { - this.file = file; - - raFile = new RandomAccessFile(file, "rw"); - } - - /** - * Performs an exclusive lock on a file, that - * this lock instance was constructed with. - * - * @throws IgniteCheckedException If failed to perform locking. The file remains open. - */ - public void lock() throws IgniteCheckedException { - lock(false); - } - - /** - * Performs a lock (shared or exclusive) on a file, that - * this lock instance was constructed with. - * - * @param shared Whether a lock is shared (non-exclusive). - * @throws IgniteCheckedException If failed to perform locking. The file remains open. - */ - public void lock(boolean shared) throws IgniteCheckedException { - if (fileLock != null) - throw new IgniteCheckedException("Already locked [lockFile=" + file + ']'); - - try { - fileLock = raFile.getChannel().tryLock(0, Long.MAX_VALUE, shared); - - if (fileLock == null) - throw new IgniteCheckedException("Failed to get exclusive lock on lock file [lockFile=" + file + ']'); - } - catch (IOException | OverlappingFileLockException e) { - throw new IgniteCheckedException("Failed to get exclusive lock on lock file [lockFile=" + file + ']', e); - } - } - - /** - * Unlocks the file. - */ - public void unlock() { - if (fileLock != null) { - U.releaseQuiet(fileLock); - - fileLock = null; - } - } - - /** - * Unlocks and closes the file. - */ - public void close() { - unlock(); - - U.closeQuiet(raFile); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridFileLock.class, this); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd28003b/modules/core/src/test/java/org/gridgain/testframework/GridJarClassLoader.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/testframework/GridJarClassLoader.java b/modules/core/src/test/java/org/gridgain/testframework/GridJarClassLoader.java deleted file mode 100644 index 28f26c9..0000000 --- a/modules/core/src/test/java/org/gridgain/testframework/GridJarClassLoader.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.testframework; - -import java.io.*; -import java.security.*; -import java.util.*; -import java.util.jar.*; - -/** - * Jar class loader. - */ -public final class GridJarClassLoader extends SecureClassLoader { - /** Cached loaded classes as bytes. */ - private final Map<String, byte[]> clsArrs; - - /** List of excluded classes/packages. */ - @SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized") - private List<String> excludedCls = new ArrayList<>(); - - /** */ - private static GridJarClassLoader instance; - - /** - * Get classloader singleton instance. - * - * @param files Files. - * @param parent Parent classloader. - * @return Instance of Jar class loader. - * @throws IOException If fies can't be read, - */ - public static synchronized GridJarClassLoader getInstance(List<String> files, ClassLoader parent) - throws IOException{ - if (instance == null) - instance = new GridJarClassLoader(files, parent); - - return instance; - } - - /** - * Constructor. - * - * @param files Files. - * @param parent Parent classloader. - * @throws IOException If fies can't be read, - */ - private GridJarClassLoader(Iterable<String> files, ClassLoader parent) throws IOException { - super(parent); - - clsArrs = new HashMap<>(); - - for (String fileName: files) - readJarFile(fileName); - } - - /** {@inheritDoc} */ - @Override protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { - boolean excluded = false; - - for (String cls: excludedCls) - if (name.startsWith(cls)) { - excluded = true; - - break; - } - - // If class is from Jar file(s) and not in excluded (note we use name with '.'). - if (clsArrs.containsKey(name) && !excluded) { - Class<?> cls = findLoadedClass(name); - - if (cls == null) - cls = findClass(name); - - if (resolve) - resolveClass(cls); - - return cls; - } - - return super.loadClass(name, resolve); - } - - - /** {@inheritDoc} */ - @Override protected Class<?> findClass(String name) throws ClassNotFoundException { - - SecurityManager sm = System.getSecurityManager(); - - if (sm != null) { - int i = name.lastIndexOf('.'); - - if (i >= 0) - sm.checkPackageDefinition(name.substring(0, i)); - } - - byte[] buf = clsArrs.get(name); - - if (buf != null) - return defineClass(name, buf, 0, buf.length, (CodeSource)null); - - throw new ClassNotFoundException(name); - } - - /** - * Reads JAR file and stored classes locally. - * - * @param fileName Name of file to read. - * @throws IOException If read failed. - */ - private void readJarFile(String fileName) throws IOException { - JarEntry je; - - JarInputStream jis = new JarInputStream(new FileInputStream(fileName)); - - while ((je = jis.getNextJarEntry()) != null) { - String jarName = je.getName(); - - if (jarName.endsWith(".class")) - loadClassBytes(jis, jarName); - - // Else ignore it; it could be an image or audio file. - jis.closeEntry(); - } - } - - /** - * Loads class bytes to storege. - * - * @param jis Input stream. - * @param jarName Name of the JAR file. - * @throws IOException If read failed. - */ - private void loadClassBytes(JarInputStream jis, String jarName) throws IOException { - BufferedInputStream jarBuf = new BufferedInputStream(jis); - ByteArrayOutputStream jarOut = new ByteArrayOutputStream(); - - int b; - - while ((b = jarBuf.read()) != -1) - jarOut.write(b); - - // Remove ".class". - String urlName = jarName.substring(0, jarName.length() - 6); - - String name = urlName.replace('/', '.'); - - clsArrs.put(name, jarOut.toByteArray()); - } - - /** - * @return the excludedCls - */ - public List<String> getExcludedCls() { - return excludedCls; - } - - /** - * @param excludedCls the excludedCls to set - */ - public void setExcludedCls(List<String> excludedCls) { - this.excludedCls = excludedCls; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd28003b/modules/core/src/test/java/org/gridgain/testframework/GridLoadTestUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/testframework/GridLoadTestUtils.java b/modules/core/src/test/java/org/gridgain/testframework/GridLoadTestUtils.java deleted file mode 100644 index 5cd0942..0000000 --- a/modules/core/src/test/java/org/gridgain/testframework/GridLoadTestUtils.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.testframework; - -import org.apache.ignite.internal.util.typedef.internal.*; -import org.jetbrains.annotations.*; - -import java.io.*; -import java.text.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; - -/** - * Utility class for load tests. - */ -public class GridLoadTestUtils { - /** Date and time format. */ - public static final SimpleDateFormat DATE_TIME_FORMAT = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); - - /** Lock file. */ - public static final File LOCK_FILE = new File(System.getProperty("user.home"), ".gg-loadtest-lock"); - - /** */ - private GridLoadTestUtils() { - // No-op. - } - - /** - * Appends a line to a file. Creates parent directories if any of those do not - * exist. - * - * @param fileName Name of a file to append to. - * @param format A line format. - * @param vals A line format args. - * @throws IOException If IO error occurs. - */ - public static void appendLineToFile(String fileName, String format, Object... vals) throws IOException { - new File(fileName).getParentFile().mkdirs(); - - try (Writer out = new BufferedWriter(new FileWriter(fileName, true))) { - out.write(String.format(format + '\n', vals)); - } - } - - /** - * Runs a given callable in loop in multiple threads for specified period of time. - * - * @param c Callable to run. - * @param threadCnt Thread count. - * @param dur Run duration in milliseconds. - */ - public static void runMultithreadedInLoop(final Callable<?> c, int threadCnt, long dur) { - ExecutorService pool = Executors.newFixedThreadPool(threadCnt); - final AtomicBoolean finish = new AtomicBoolean(); - - for (int i = 0; i < threadCnt; i++) - pool.submit(new Callable<Object>() { - @Nullable @Override public Object call() throws Exception { - while (!finish.get()) - c.call(); - - return null; - } - }); - - try { - Thread.sleep(dur); - } - catch (InterruptedException ignored) { - // No-op. - } - - finish.set(true); - - pool.shutdown(); - } - - /** - * Performs operation, measuring it's time. - * - * @param c Operation to perform. - * @param threadCnt Number of parallel threads to perform operation (>= 1). - * @return Number of milliseconds, in which the operation was completed. - * @throws Exception If provided callable has thrown exception. - */ - public static long measureTime(Callable<Object> c, int threadCnt) throws Exception { - A.ensure(threadCnt >= 1, "threadCnt should be >= 1"); - - long start = System.currentTimeMillis(); - - if (threadCnt == 1) - c.call(); - else - GridTestUtils.runMultiThreaded(c, threadCnt, "test-worker"); - - return System.currentTimeMillis() - start; - } - - /** - * Starts a daemon thread. - * - * @param r Thread runnable. - * @return Started daemon thread. - */ - public static Thread startDaemon(Runnable r) { - Thread t = new Thread(r); - - t.setDaemon(true); - - t.start(); - - return t; - } - - /** - * Returns a new instance of {@link GridFileLock}, that - * can be used to synchronize on a lock file, which resides - * in a temporary directory. - * <p> - * If a lock file does not exist, it is created. - * <p> - * If a temporary directory does not exist, an exception is - * thrown. - * - * @return An file lock instance. Calling {@link GridFileLock#lock()} - * will perform actual locking. - * @throws RuntimeException If a temporary directory is not found. - */ - public static GridFileLock fileLock() { - try { - return new GridFileLock(LOCK_FILE); - } - catch (FileNotFoundException e) { - throw new RuntimeException("tmp.dir not found", e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd28003b/modules/core/src/test/java/org/gridgain/testframework/GridSpiTestContext.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/testframework/GridSpiTestContext.java b/modules/core/src/test/java/org/gridgain/testframework/GridSpiTestContext.java deleted file mode 100644 index 5aa316b..0000000 --- a/modules/core/src/test/java/org/gridgain/testframework/GridSpiTestContext.java +++ /dev/null @@ -1,563 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.testframework; - -import org.apache.ignite.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.events.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.plugin.security.*; -import org.apache.ignite.spi.*; -import org.apache.ignite.spi.discovery.*; -import org.apache.ignite.spi.swapspace.*; -import org.apache.ignite.internal.managers.communication.*; -import org.apache.ignite.internal.managers.eventstorage.*; -import org.apache.ignite.internal.util.direct.*; -import org.apache.ignite.internal.util.typedef.*; -import org.jetbrains.annotations.*; - -import java.io.*; -import java.nio.*; -import java.util.*; -import java.util.concurrent.*; - -import static org.apache.ignite.events.IgniteEventType.*; - -/** - * Test SPI context. - */ -public class GridSpiTestContext implements IgniteSpiContext { - /** */ - private final Collection<ClusterNode> rmtNodes = new ConcurrentLinkedQueue<>(); - - /** */ - private ClusterNode locNode; - - /** */ - private final Map<GridLocalEventListener, Set<Integer>> evtLsnrs = new HashMap<>(); - - /** */ - @SuppressWarnings("deprecation") - private final Collection<GridMessageListener> msgLsnrs = new ArrayList<>(); - - /** */ - private final Map<ClusterNode, Serializable> sentMsgs = new HashMap<>(); - - /** */ - private final ConcurrentMap<String, Map> cache = new ConcurrentHashMap<>(); - - /** {@inheritDoc} */ - @Override public Collection<ClusterNode> remoteNodes() { - return rmtNodes; - } - - /** {@inheritDoc} */ - @Override public ClusterNode localNode() { - return locNode; - } - - /** {@inheritDoc} */ - @Override public Collection<ClusterNode> remoteDaemonNodes() { - Collection<ClusterNode> daemons = new ArrayList<>(); - - for (ClusterNode node : rmtNodes) { - if (node.isDaemon()) - daemons.add(node); - } - - return daemons; - } - - /** {@inheritDoc} */ - @Override public Collection<ClusterNode> nodes() { - Collection<ClusterNode> all = new ArrayList<>(rmtNodes); - - if (locNode != null) - all.add(locNode); - - return all; - } - - /** - * @param locNode Local node. - */ - public void setLocalNode(@Nullable ClusterNode locNode) { - this.locNode = locNode; - } - - /** {@inheritDoc} */ - @Nullable @Override - public ClusterNode node(UUID nodeId) { - if (locNode != null && locNode.id().equals(nodeId)) - return locNode; - - for (ClusterNode node : rmtNodes) { - if (node.id().equals(nodeId)) - return node; - } - - return null; - } - - /** */ - public void createLocalNode() { - setLocalNode(new GridTestNode(UUID.randomUUID(), createMetrics(1, 1))); - } - - /** - * @param cnt Number of nodes. - */ - public void createRemoteNodes(int cnt) { - for (int i = 0; i < cnt; i++) - addNode(new GridTestNode(UUID.randomUUID(), createMetrics(1, 1))); - } - - /** */ - public void reset() { - setLocalNode(null); - - rmtNodes.clear(); - } - - /** - * @param waitingJobs Waiting jobs count. - * @param activeJobs Active jobs count. - * @return Metrics adapter. - */ - private DiscoveryNodeMetricsAdapter createMetrics(int waitingJobs, int activeJobs) { - DiscoveryNodeMetricsAdapter metrics = new DiscoveryNodeMetricsAdapter(); - - metrics.setCurrentWaitingJobs(waitingJobs); - metrics.setCurrentActiveJobs(activeJobs); - - return metrics; - } - - /** - * @param nodes Nodes to reset. - * @param rmv Whether nodes that were not passed in should be removed or not. - */ - public void resetNodes(Collection<ClusterNode> nodes, boolean rmv) { - for (ClusterNode node : nodes) { - assert !node.equals(locNode); - - if (!rmtNodes.contains(node)) - addNode(node); - } - - if (rmv) { - for (Iterator<ClusterNode> iter = rmtNodes.iterator(); iter.hasNext();) { - ClusterNode node = iter.next(); - - if (!nodes.contains(node)) { - iter.remove(); - - notifyListener(new IgniteDiscoveryEvent(locNode, "Node left", EVT_NODE_LEFT, node)); - } - } - } - } - - /** - * @param node Node to check. - * @return {@code True} if the node is local. - */ - public boolean isLocalNode(ClusterNode node) { - return locNode.equals(node); - } - - /** - * @param node Node to add. - */ - public void addNode(ClusterNode node) { - rmtNodes.add(node); - - notifyListener(new IgniteDiscoveryEvent(locNode, "Node joined", EVT_NODE_JOINED, node)); - } - - /** - * @param node Node to remove. - */ - public void removeNode(ClusterNode node) { - if (rmtNodes.remove(node)) - notifyListener(new IgniteDiscoveryEvent(locNode, "Node left", EVT_NODE_LEFT, node)); - } - - /** - * @param nodeId Node ID. - */ - public void removeNode(UUID nodeId) { - for (Iterator<ClusterNode> iter = rmtNodes.iterator(); iter.hasNext();) { - ClusterNode node = iter.next(); - - if (node.id().equals(nodeId)) { - iter.remove(); - - notifyListener(new IgniteDiscoveryEvent(locNode, "Node left", EVT_NODE_LEFT, node)); - } - } - } - - /** - * @param node Node to fail. - */ - public void failNode(ClusterNode node) { - if (rmtNodes.remove(node)) - notifyListener(new IgniteDiscoveryEvent(locNode, "Node failed", EVT_NODE_FAILED, node)); - } - - /** - * @param node Node for metrics update. - */ - public void updateMetrics(ClusterNode node) { - if (locNode.equals(node) || rmtNodes.contains(node)) - notifyListener(new IgniteDiscoveryEvent(locNode, "Metrics updated.", EVT_NODE_METRICS_UPDATED, node)); - } - - /** */ - public void updateAllMetrics() { - notifyListener(new IgniteDiscoveryEvent(locNode, "Metrics updated", EVT_NODE_METRICS_UPDATED, locNode)); - - for (ClusterNode node : rmtNodes) { - notifyListener(new IgniteDiscoveryEvent(locNode, "Metrics updated", EVT_NODE_METRICS_UPDATED, node)); - } - } - - /** - * @param evt Event node. - */ - private void notifyListener(IgniteEvent evt) { - assert evt.type() > 0; - - for (Map.Entry<GridLocalEventListener, Set<Integer>> entry : evtLsnrs.entrySet()) { - if (F.isEmpty(entry.getValue()) || entry.getValue().contains(evt.type())) - entry.getKey().onEvent(evt); - } - } - - /** {@inheritDoc} */ - @Override public boolean pingNode(UUID nodeId) { - return node(nodeId) != null; - } - - /** {@inheritDoc} */ - @Override public void send(ClusterNode node, Serializable msg, String topic) - throws IgniteSpiException { - sentMsgs.put(node, msg); - } - - /** - * @param node Node message was sent to. - * @return Sent message. - */ - public Serializable getSentMessage(ClusterNode node) { - return sentMsgs.get(node); - } - - /** - * @param node Node message was sent to. - * @return Sent message. - */ - public Serializable removeSentMessage(ClusterNode node) { - return sentMsgs.remove(node); - } - - /** - * @param node Destination node. - * @param msg Message. - */ - @SuppressWarnings("deprecation") - public void triggerMessage(ClusterNode node, Object msg) { - for (GridMessageListener lsnr : msgLsnrs) { - lsnr.onMessage(node.id(), msg); - } - } - - /** {@inheritDoc} */ - @SuppressWarnings("deprecation") - @Override public void addMessageListener(GridMessageListener lsnr, String topic) { - msgLsnrs.add(lsnr); - } - - /** {@inheritDoc} */ - @SuppressWarnings("deprecation") - @Override public boolean removeMessageListener(GridMessageListener lsnr, String topic) { - return msgLsnrs.remove(lsnr); - } - - /** - * @param type Event type. - * @param taskName Task name. - * @param taskSesId Session ID. - * @param msg Event message. - */ - public void triggerTaskEvent(int type, String taskName, IgniteUuid taskSesId, String msg) { - assert type > 0; - - triggerEvent(new IgniteTaskEvent(locNode, msg, type, taskSesId, taskName, null, false, null)); - } - - /** - * @param evt Event to trigger. - */ - public void triggerEvent(IgniteEvent evt) { - notifyListener(evt); - } - - /** {@inheritDoc} */ - @Override public void addLocalEventListener(GridLocalEventListener lsnr, int... types) { - Set<Integer> typeSet = F.addIfAbsent(evtLsnrs, lsnr, F.<Integer>newSet()); - - assert typeSet != null; - - if (types != null) { - for (int type : types) { - typeSet.add(type); - } - } - } - - /** {@inheritDoc} */ - @Override public boolean removeLocalEventListener(GridLocalEventListener lsnr) { - boolean res = evtLsnrs.containsKey(lsnr); - - evtLsnrs.remove(lsnr); - - return res; - } - - /** {@inheritDoc} */ - @Override public boolean isEventRecordable(int... types) { - return true; - } - - /** {@inheritDoc} */ - @Override public void recordEvent(IgniteEvent evt) { - notifyListener(evt); - } - - /** {@inheritDoc} */ - @Override public void registerPort(int port, IgnitePortProtocol proto) { - /* No-op. */ - } - - /** {@inheritDoc} */ - @Override public void deregisterPort(int port, IgnitePortProtocol proto) { - /* No-op. */ - } - - /** {@inheritDoc} */ - @Override public void deregisterPorts() { - /* No-op. */ - } - - /** {@inheritDoc} */ - @Override public <K, V> V get(String cacheName, K key) throws IgniteCheckedException { - assert cacheName != null; - assert key != null; - - V res = null; - - Map<K, CachedObject<V>> cache = getOrCreateCache(cacheName); - - CachedObject<V> obj = cache.get(key); - - if (obj != null) { - if (obj.expire == 0 || obj.expire > System.currentTimeMillis()) - res = obj.obj; - else - cache.remove(key); - } - - return res; - } - - /** {@inheritDoc} */ - @Override public <K, V> V put(String cacheName, K key, V val, long ttl) throws IgniteCheckedException { - assert cacheName != null; - assert key != null; - assert ttl >= 0; - - long expire = ttl > 0 ? System.currentTimeMillis() + ttl : 0; - - CachedObject<V> obj = new CachedObject<>(expire, val); - - Map<K, CachedObject<V>> cache = getOrCreateCache(cacheName); - - CachedObject<V> prev = cache.put(key, obj); - - return prev != null ? prev.obj : null; - } - - /** {@inheritDoc} */ - @SuppressWarnings({"unchecked"}) - @Override public <K, V> V putIfAbsent(String cacheName, K key, V val, long ttl) throws IgniteCheckedException { - V v = get(cacheName, key); - - if (v != null) - return put(cacheName, key, val, ttl); - - return v; - } - - /** {@inheritDoc} */ - @Override public <K, V> V remove(String cacheName, K key) throws IgniteCheckedException { - assert cacheName != null; - assert key != null; - - Map<K, CachedObject<V>> cache = getOrCreateCache(cacheName); - - CachedObject<V> prev = cache.remove(key); - - return prev != null ? prev.obj : null; - } - - /** {@inheritDoc} */ - @Override public <K> boolean containsKey(String cacheName, K key) { - assert cacheName != null; - assert key != null; - - boolean res = false; - - try { - res = get(cacheName, key) != null; - } - catch (IgniteCheckedException ignored) { - - } - - return res; - } - - /** {@inheritDoc} */ - @Override public void writeToSwap(String spaceName, Object key, @Nullable Object val, - @Nullable ClassLoader ldr) throws IgniteCheckedException { - /* No-op. */ - } - - /** {@inheritDoc} */ - @Override public <T> T readFromSwap(String spaceName, SwapKey key, @Nullable ClassLoader ldr) - throws IgniteCheckedException { - return null; - } - - /** {@inheritDoc} */ - @Override public <T> T readFromOffheap(String spaceName, int part, Object key, byte[] keyBytes, - @Nullable ClassLoader ldr) throws IgniteCheckedException { - return null; - } - - /** {@inheritDoc} */ - @Override public boolean removeFromOffheap(@Nullable String spaceName, int part, Object key, - @Nullable byte[] keyBytes) throws IgniteCheckedException { - return false; - } - - /** {@inheritDoc} */ - @Override public void writeToOffheap(@Nullable String spaceName, int part, Object key, @Nullable byte[] keyBytes, - Object val, @Nullable byte[] valBytes, @Nullable ClassLoader ldr) throws IgniteCheckedException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public int partition(String cacheName, Object key) { - return -1; - } - - /** {@inheritDoc} */ - @Override public void removeFromSwap(String spaceName, Object key, - @Nullable ClassLoader ldr) throws IgniteCheckedException { - // No-op. - } - - /** {@inheritDoc} */ - @Nullable @Override public IgniteSpiNodeValidationResult validateNode(ClusterNode node) { - return null; - } - - /** {@inheritDoc} */ - @Override public boolean writeDelta(UUID nodeId, Object msg, ByteBuffer buf) { - return false; - } - - /** {@inheritDoc} */ - @Override public boolean readDelta(UUID nodeId, Class<?> msgCls, ByteBuffer buf) { - return false; - } - - /** {@inheritDoc} */ - @Override public Collection<GridSecuritySubject> authenticatedSubjects() throws IgniteCheckedException { - return Collections.emptyList(); - } - - /** {@inheritDoc} */ - @Override public GridSecuritySubject authenticatedSubject(UUID subjId) throws IgniteCheckedException { - return null; - } - - /** {@inheritDoc} */ - @Nullable @Override public <T> T readValueFromOffheapAndSwap(@Nullable String spaceName, Object key, - @Nullable ClassLoader ldr) throws IgniteCheckedException { - return null; - } - - /** {@inheritDoc} */ - @Override public GridTcpMessageFactory messageFactory() { - return new GridTcpMessageFactory() { - @Override public GridTcpCommunicationMessageAdapter create(byte type) { - return GridTcpCommunicationMessageFactory.create(type); - } - }; - } - - /** - * @param cacheName Cache name. - * @return Map representing cache. - */ - @SuppressWarnings("unchecked") - private <K, V> Map<K, V> getOrCreateCache(String cacheName) { - synchronized (cache) { - Map<K, V> map = cache.get(cacheName); - - if (map == null) - cache.put(cacheName, map = new ConcurrentHashMap<>()); - - return map; - } - } - - /** - * Cached object. - */ - private static class CachedObject<V> { - /** */ - private long expire; - - /** */ - private V obj; - - /** - * @param expire Expire time. - * @param obj Object. - */ - private CachedObject(long expire, V obj) { - this.expire = expire; - this.obj = obj; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd28003b/modules/core/src/test/java/org/gridgain/testframework/GridStringLogger.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/testframework/GridStringLogger.java b/modules/core/src/test/java/org/gridgain/testframework/GridStringLogger.java deleted file mode 100644 index 9334f40..0000000 --- a/modules/core/src/test/java/org/gridgain/testframework/GridStringLogger.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.testframework; - -import org.apache.ignite.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.jetbrains.annotations.*; - -/** - * Logger which logs to string buffer. - */ -public class GridStringLogger implements IgniteLogger { - /** */ - private static final int MAX = 1024 * 11; - - /** */ - private static final int CHAR_CNT = 1024 * 10; - - /** */ - private StringBuilder buf = new StringBuilder(MAX); - - /** */ - private final boolean dbg; - - /** */ - private final IgniteLogger echo; - - /** - * - */ - public GridStringLogger() { - this(false); - } - - /** - * @param dbg Debug flag. - */ - public GridStringLogger(boolean dbg) { - this(dbg, null); - } - - /** - * @param dbg Debug flag. - * @param echo Logger to echo all messages. - */ - public GridStringLogger(boolean dbg, @Nullable IgniteLogger echo) { - this.dbg = dbg; - this.echo = echo; - } - - /** - * @param msg Message to log. - */ - private void log(String msg) { - buf.append(msg).append(U.nl()); - - if (echo != null) - echo.info("[GridStringLogger echo] " + msg); - - if (buf.length() > CHAR_CNT) { - if (echo != null) - echo.warning("Cleaning GridStringLogger history."); - - buf.delete(0, buf.length() - CHAR_CNT); - } - - assert buf.length() <= CHAR_CNT; - } - - /** {@inheritDoc} */ - @Override public IgniteLogger getLogger(Object ctgr) { - return this; - } - - /** {@inheritDoc} */ - @Override public void trace(String msg) { - log(msg); - } - - /** {@inheritDoc} */ - @Override public void debug(String msg) { - log(msg); - } - - /** {@inheritDoc} */ - @Override public void info(String msg) { - log(msg); - } - - /** {@inheritDoc} */ - @Override public void warning(String msg) { - log(msg); - } - - /** {@inheritDoc} */ - @Override public void warning(String msg, @Nullable Throwable e) { - log(msg); - - if (e != null) - log(e.toString()); - } - - /** {@inheritDoc} */ - @Override public void error(String msg) { - log(msg); - } - - /** {@inheritDoc} */ - @Override public void error(String msg, @Nullable Throwable e) { - log(msg); - - if (e != null) - log(e.toString()); - } - - /** {@inheritDoc} */ - @Override public boolean isTraceEnabled() { - return dbg; - } - - /** {@inheritDoc} */ - @Override public boolean isDebugEnabled() { - return dbg; - } - - /** {@inheritDoc} */ - @Override public boolean isInfoEnabled() { - return true; - } - - /** {@inheritDoc} */ - @Override public boolean isQuiet() { - return false; - } - - /** {@inheritDoc} */ - @Nullable @Override public String fileName() { - return null; - } - - /** - * Resets logger. - */ - public void reset() { - buf.setLength(0); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return buf.toString(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd28003b/modules/core/src/test/java/org/gridgain/testframework/GridTestClassLoader.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/testframework/GridTestClassLoader.java b/modules/core/src/test/java/org/gridgain/testframework/GridTestClassLoader.java deleted file mode 100644 index 8bcdc17..0000000 --- a/modules/core/src/test/java/org/gridgain/testframework/GridTestClassLoader.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.testframework; - -import org.apache.ignite.internal.util.*; -import org.jetbrains.annotations.*; - -import java.io.*; -import java.util.*; - -/** - * Test class loader. - */ -public class GridTestClassLoader extends ClassLoader { - /** */ - private final Map<String, String> rsrcs; - - /** */ - private final String[] clsNames; - - /** - * @param clsNames Test Class names. - */ - public GridTestClassLoader(String... clsNames) { - this(null, GridTestClassLoader.class.getClassLoader(), clsNames); - } - - /** - * @param clsNames Test Class name. - * @param rsrcs Resources. - */ - public GridTestClassLoader(Map<String, String> rsrcs, String... clsNames) { - this(rsrcs, GridTestClassLoader.class.getClassLoader(), clsNames); - } - - /** - * @param clsNames Test Class name. - * @param rsrcs Resources. - * @param parent Parent class loader. - */ - public GridTestClassLoader(@Nullable Map<String, String> rsrcs, ClassLoader parent, String... clsNames) { - super(parent); - - this.rsrcs = rsrcs; - this.clsNames = clsNames; - } - - /** {@inheritDoc} */ - @Override protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { - Class<?> res = findLoadedClass(name); - - if (res != null) - return res; - - boolean patch = false; - - for (String clsName : clsNames) - if (name.equals(clsName)) - patch = true; - - if (patch) { - String path = name.replaceAll("\\.", "/") + ".class"; - - InputStream in = getResourceAsStream(path); - - if (in != null) { - GridByteArrayList bytes = new GridByteArrayList(1024); - - try { - bytes.readAll(in); - } - catch (IOException e) { - throw new ClassNotFoundException("Failed to upload class ", e); - } - - return defineClass(name, bytes.internalArray(), 0, bytes.size()); - } - - throw new ClassNotFoundException("Failed to upload resource [class=" + path + ", parent classloader=" - + getParent() + ']'); - } - - // Maybe super knows. - return super.loadClass(name, resolve); - } - - /** {@inheritDoc} */ - @SuppressWarnings("deprecation") - @Override public InputStream getResourceAsStream(String name) { - if (rsrcs != null && rsrcs.containsKey(name)) - return new StringBufferInputStream(rsrcs.get(name)); - - return getParent().getResourceAsStream(name); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd28003b/modules/core/src/test/java/org/gridgain/testframework/GridTestExternalClassLoader.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/testframework/GridTestExternalClassLoader.java b/modules/core/src/test/java/org/gridgain/testframework/GridTestExternalClassLoader.java deleted file mode 100644 index b8e6cba..0000000 --- a/modules/core/src/test/java/org/gridgain/testframework/GridTestExternalClassLoader.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.testframework; - -import org.jetbrains.annotations.*; - -import java.io.*; -import java.net.*; -import java.util.*; - -/** - * Utility classloader that has ability to load classes from external resources. - */ -@SuppressWarnings({"CustomClassloader"}) -public class GridTestExternalClassLoader extends URLClassLoader { - /** */ - private Set<String> excludeClassNames; - - /** */ - private Map<String, byte[]> resourceMap; - - /** */ - private long timeout; - - /** - * Constructor. - * @param urls the URLs from which to load classes and resources. - * @param excludeClassNames list of excluded classes. - */ - public GridTestExternalClassLoader(URL[] urls, String... excludeClassNames) { - this(urls, Collections.<String, byte[]>emptyMap(), excludeClassNames); - } - - /** - * Constructor. - * @param urls the URLs from which to load classes and resources. - * @param resourceMap mapped resources. - */ - public GridTestExternalClassLoader(URL[] urls, Map<String, byte[]> resourceMap) { - this(urls, resourceMap, Collections.<String>emptySet()); - } - - /** - * Constructor. - * @param urls the URLs from which to load classes and resources. - * @param resourceMap Resource map. - * @param excludeClassNames list of excluded classes. - */ - public GridTestExternalClassLoader(URL[] urls, Map<String, byte[]> resourceMap, String... excludeClassNames) { - this(urls, resourceMap, new HashSet<>(Arrays.asList(excludeClassNames))); - } - - /** - * Constructor. - * @param urls the URLs from which to load classes and resources. - * @param resourceMap Resource map. - * @param excludeClassNames list of excluded classes. - */ - public GridTestExternalClassLoader(URL[] urls, Map<String, byte[]> resourceMap, Set<String> excludeClassNames) { - super(urls, GridTestExternalClassLoader.class.getClassLoader()); - - this.excludeClassNames = excludeClassNames; - - assert resourceMap != null; - - this.resourceMap = resourceMap; - } - - /** - * Sets set of excluded resource paths. - * @param excludeClassNames excluded resource paths. - */ - public void setExcludeClassNames(Set<String> excludeClassNames) { - this.excludeClassNames = excludeClassNames; - } - - /** - * Sets set of excluded resource paths. - * @param excludeClassNames excluded resource paths. - */ - public void setExcludeClassNames(String... excludeClassNames) { - setExcludeClassNames(new HashSet<>(Arrays.asList(excludeClassNames))); - } - - /** - * @param timeout Timeout. - */ - public void setTimeout(long timeout) { - this.timeout = timeout; - } - - /** - * Sleep {@code timeout} period of time. - */ - private void doTimeout() { - try { - Thread.sleep(timeout); - } - catch (InterruptedException e) { - throw new RuntimeException("Thread was interrupted", e); - } - } - - /** - * @param resName Resource name. - * @return Class name. - */ - private String resNameToClassName(String resName) { - if (resName.endsWith(".class")) - resName = resName.substring(0, resName.length() - ".class".length()); - - return resName.replace('/', '.'); - } - - /** {@inheritDoc} */ - @Override protected Class<?> findClass(String name) throws ClassNotFoundException { - for (String s : excludeClassNames) - if (s.equals(name)) - throw new ClassNotFoundException(name); - - return super.findClass(name); - } - - /** {@inheritDoc} */ - @SuppressWarnings({"NonSynchronizedMethodOverridesSynchronizedMethod"}) - @Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { - if (excludeClassNames.contains(name)) - throw new ClassNotFoundException(name); - - return super.loadClass(name, resolve); - } - - /** {@inheritDoc} */ - @Nullable @Override public URL findResource(String name) { - if (excludeClassNames.contains(resNameToClassName(name))) - return null; - - return super.findResource(name); - } - - /** {@inheritDoc} */ - @Override public InputStream getResourceAsStream(String name) { - doTimeout(); - - byte[] res = resourceMap.get(name); - - return res == null ? super.getResourceAsStream(name) : new ByteArrayInputStream(res); - } - - /** - * @param resourceMap mapped resources. - */ - public void setResourceMap(Map<String, byte[]> resourceMap) { - this.resourceMap = resourceMap; - } - - /** - * Returns an Enumeration of URLs representing all of the resources on the URL search path having the specified name. - * - * @param name the resource name. - * @return an {@code Enumeration} of {@code URL}s. - * @throws IOException if an I/O exception occurs. - */ - @Override public Enumeration<URL> findResources(String name) throws IOException { - if (excludeClassNames.contains(resNameToClassName(name))) { - return new Enumeration<URL>() { - @Override public boolean hasMoreElements() { - return false; - } - - @Override public URL nextElement() { - throw new UnsupportedOperationException(); - } - }; - } - - return super.findResources(name); - } -}