@Override public void afterTestClass(TestContext testContext) throws Exception { TestResourceTracker.testFinished(testContext.getTestClass().getName()); } }
@BeforeClass(alwaysRun = true) protected final void testClassStarted(ITestContext context) { TestResourceTracker.testStarted(getTestName()); }
/** * A stress test. One node is constantly modified using transactions while a rehash occurs. */ @Test(groups = "stress", timeOut = 15*60*1000) public void testTransactionalStress() throws Throwable { TestResourceTracker.testThreadStarted(this); stressTest(true); }
/** * Add a resource to the current thread's running test. */ public static void addResource(Cleaner<?> cleaner) { String testName = getCurrentTestName(); addResource(testName, cleaner); }
/** * Called on the "main" test thread, after any configuration method. */ public static void testFinished(String testName) { cleanUpResources(testName); if (!testName.equals(threadTestName.get())) { cleanUpResources(getCurrentTestName()); throw new IllegalArgumentException("Current thread's test name was not set correctly: " + getCurrentTestName() + ", should have been " + testName); } setThreadTestName(null); }
/** * Called on the "main" test thread, before any configuration method. */ public static void testStarted(String testName) { if (testResources.containsKey(testName)) { throw new IllegalStateException("Two tests with the same name running in parallel: " + testName); } setThreadTestName(testName); Thread.currentThread().setName(getNextTestThreadName()); }
BatchingClient(int port) { this.port = port; DefaultThreadFactory threadFactory = new DefaultThreadFactory(TestResourceTracker.getCurrentTestShortName()); group = new NioEventLoopGroup(0, threadFactory); }
@Override public void evaluate() throws Throwable { TestResourceTracker.testStarted( testName ); try { base.evaluate(); } finally { TestResourceTracker.testFinished( testName ); } } };
@Test(timeOut = 30000, dataProvider = "startOrder") public void testConcurrentStart(int eagerManager, int lazyManager) throws Exception { TestResourceTracker.testThreadStarted(this); String name1 = TestResourceTracker.getNextNodeName(); String name2 = TestResourceTracker.getNextNodeName();
public static String getNextNodeName() { String testName = getCurrentTestName(); TestResources resources = getTestResources(testName); String shortName = resources.getShortName(); int nextNodeIndex = resources.addNode(); return shortName + "-" + "Node" + getNameForIndex(nextNodeIndex); }
public void amendConfiguration(ConfigurationBuilderHolder holder) { TransportConfigurationBuilder transport = holder.getGlobalConfigurationBuilder().transport(); transport.nodeName(TestResourceTracker.getNextNodeName()); transport.clusterName(TestResourceTracker.getCurrentTestName()); // minimize number of threads using unlimited cached thread pool transport.remoteCommandThreadPool().threadPoolFactory(CachedThreadPoolExecutorFactory.create()); transport.transportThreadPool().threadPoolFactory(CachedThreadPoolExecutorFactory.create()); for (Map.Entry<String, ConfigurationBuilder> cfg : holder.getNamedConfigurationBuilders().entrySet()) { amendCacheConfiguration(cfg.getKey(), cfg.getValue()); } // disable simple cache for testing as we need to insert interceptors if (!pendingPutsSimple) { holder.getNamedConfigurationBuilders().get(DEF_PENDING_PUTS_RESOURCE).simpleCache(false); } }
public static String getCurrentTestShortName() { String currentTestName = TestResourceTracker.getCurrentTestName(); return getTestResources(currentTestName).getShortName(); }
public void joinContext() { TestResourceTracker.setThreadTestName( runningTest ); }
@Override protected void parseSiteConfiguration(Map<String, RelayConfig.SiteConfig> map) throws Exception { super.parseSiteConfiguration(map); String testName = TestResourceTracker.getCurrentTestName(); map.forEach((s, siteConfig) -> { List<RelayConfig.BridgeConfig> bridges = siteConfig.getBridges(); for (int i = 0; i < bridges.size(); i++) { RelayConfig.BridgeConfig bridgeConfig = bridges.get(i); String config = (String) TestingUtil.extractField(RelayConfig.PropertiesBridgeConfig.class, bridgeConfig, "config"); // Keep the same ports for all the tests, just change the cluster name String clusterName = "bridge-" + (testName != null ? testName : "namenotset"); bridges.set(i, new RelayConfig.PropertiesBridgeConfig(clusterName, config)); } }); } }
/** * Produces the default embedded cache manager. * * @param defaultConfiguration the default configuration produced by the {@link DefaultTestEmbeddedCacheManagerProducer}. * @return the default embedded cache manager used by the application. */ @Produces @ApplicationScoped public EmbeddedCacheManager getDefaultEmbeddedCacheManager(Configuration defaultConfiguration) { // Sometimes we're called from a remote thread that doesn't have the test name set // We don't have the test name here, either, but we can use a dummy one TestResourceTracker.setThreadTestNameIfMissing("DefaultTestEmbeddedCacheManagerProducer"); ConfigurationBuilder builder = new ConfigurationBuilder(); GlobalConfigurationBuilder globalConfigurationBuilder = new GlobalConfigurationBuilder(); builder.read(defaultConfiguration); return TestCacheManagerFactory.createClusteredCacheManager(globalConfigurationBuilder, builder); }
public static void setNodeName(GlobalConfigurationBuilder builder) { String nextNodeName = TestResourceTracker.getNextNodeName(); // Set the node name even for local managers in order to set the name of the worker threads builder.transport().nodeName(nextNodeName); }
@BeforeClass public void setUp() throws Exception { IntStream.range(0, getNumNodes()).forEach(n -> { RestServerHelper restServer = new RestServerHelper(cacheManagers.get(n)); restServer.start(TestResourceTracker.getCurrentTestShortName()); restServers.add(restServer); }); client = new HttpClient(); client.start(); String protoFile = Util.getResourceAsString(PROTO_FILE_NAME, getClass().getClassLoader()); registerProtobuf(PROTO_FILE_NAME, protoFile); populateData(); }
@Test(timeOut = 60000, dataProvider = "startOrder") public void testConcurrentStart(int eagerManager, int lazyManager) throws Exception { TestResourceTracker.testThreadStarted(this); String name1 = TestResourceTracker.getNextNodeName(); String name2 = TestResourceTracker.getNextNodeName();
/** * Should be called by the user on any "background" test thread that creates resources, e.g. at the beginning of a * test with a {@code @Test(timeout=n)} annotation. */ public static void testThreadStarted(AbstractInfinispanTest testInstance) { setThreadTestName(testInstance.getTestName()); Thread.currentThread().setName(getNextTestThreadName()); }
public static String getNextTestThreadName() { String testName = getCurrentTestName(); TestResources resources = getTestResources(testName); String shortName = resources.getShortName(); int nextThreadIndex = resources.addThread(); return "testng-" + shortName + (nextThreadIndex != 0 ? "-" + nextThreadIndex : ""); }