/** {@inheritDoc} */ @Override public Serializable execute() { synchronized (mux) { execCnt++; } if (log.isInfoEnabled()) log.info("Executing job: " + jobCtx.getJobId()); long now = System.currentTimeMillis(); while (!isCancelled && now < thresholdTime) { synchronized (mux) { try { mux.wait(thresholdTime - now); } catch (InterruptedException ignored) { // No-op. } } now = System.currentTimeMillis(); } synchronized (mux) { return isCancelled ? 1 : 0; } }
/** @throws Exception If failed. */ public void testAntGarTaskToString() throws Exception { String tmpDirName = GridTestProperties.getProperty("ant.gar.tmpdir"); String srcDirName = GridTestProperties.getProperty("ant.gar.srcdir"); String baseDirName = tmpDirName + File.separator + System.currentTimeMillis() + "_6"; String metaDirName = baseDirName + File.separator + "META-INF"; String garFileName = baseDirName + ".gar"; // Make base and META-INF dir. boolean mkdir = new File(baseDirName).mkdirs(); assert mkdir; mkdir = new File(metaDirName).mkdirs(); assert mkdir; // Copy files to basedir U.copy(new File(srcDirName), new File(baseDirName), true); IgniteDeploymentGarAntTask garTask = new IgniteDeploymentGarAntTask(); Project garProject = new Project(); garProject.setName("Gar test project"); garTask.setDestFile(new File(garFileName)); garTask.setBasedir(new File(garFileName)); garTask.setProject(garProject); garTask.setDescrdir(new File(garFileName)); garTask.toString(); }
/** @throws Exception If failed. */ @SuppressWarnings({"TypeMayBeWeakened"}) public void testCorrectAntGarTask() throws Exception { String tmpDirName = GridTestProperties.getProperty("ant.gar.tmpdir"); String srcDirName = GridTestProperties.getProperty("ant.gar.srcdir"); String baseDirName = tmpDirName + File.separator + System.currentTimeMillis() + "_0"; String metaDirName = baseDirName + File.separator + "META-INF"; String garFileName = baseDirName + ".gar"; String garDescDirName = U.resolveIgnitePath(GridTestProperties.getProperty("ant.gar.descriptor.dir")) .getAbsolutePath() + File.separator + "ignite.xml"; // Make base and META-INF dir. boolean mkdir = new File(baseDirName).mkdirs(); assert mkdir; mkdir = new File(metaDirName).mkdirs(); assert mkdir; // Make Gar file U.copy(new File(garDescDirName), new File(metaDirName + File.separator + "ignite.xml"), true); // Copy files to basedir U.copy(new File(srcDirName), new File(baseDirName), true); IgniteDeploymentGarAntTask garTask = new IgniteDeploymentGarAntTask(); Project garProject = new Project(); garProject.setName("Gar test project"); garTask.setDestFile(new File(garFileName)); garTask.setBasedir(new File(baseDirName)); garTask.setProject(garProject); garTask.execute(); File garFile = new File(garFileName); assert garFile.exists(); boolean res = checkStructure(garFile, true); assert res; }
/** @throws Exception If failed. */ public void testAntGarTaskWithDoubleP2PDescriptor() throws Exception { String tmpDirName = GridTestProperties.getProperty("ant.gar.tmpdir"); String srcDirName = GridTestProperties.getProperty("ant.gar.srcdir"); String baseDirName = tmpDirName + File.separator + System.currentTimeMillis() + "_2"; String metaDirName = baseDirName + File.separator + "META-INF"; String garFileName = baseDirName + ".gar"; String garDescrDirName = U.resolveIgnitePath(GridTestProperties.getProperty("ant.gar.descriptor.dir")) .getAbsolutePath() + File.separator + "ignite.xml"; // Make base and META-INF dir. boolean mkdir = new File(baseDirName).mkdirs(); assert mkdir; mkdir = new File(metaDirName).mkdirs(); assert mkdir; // Make Gar file U.copy(new File(garDescrDirName), new File(metaDirName + File.separator + "ignite.xml"), true); // Copy files to basedir U.copy(new File(srcDirName), new File(baseDirName), true); IgniteDeploymentGarAntTask garTask = new IgniteDeploymentGarAntTask(); Project garProject = new Project(); garProject.setName("Gar test project"); garTask.setDestFile(new File(garFileName)); garTask.setDescrdir(new File(garDescrDirName)); garTask.setBasedir(new File(baseDirName)); garTask.setProject(garProject); try { garTask.execute(); assert false; } catch (BuildException e) { if (log().isInfoEnabled()) log().info(e.getMessage()); } }
public GridCancelTestJob() { thresholdTime = System.currentTimeMillis() + maxJobExecTime; }
/** * @param cacheMode Cache mode. * @param sameAff If {@code false} uses different number of partitions for caches. * @param concurrency Transaction concurrency. * @param isolation Transaction isolation. * @throws Exception If failed. */ private void crossCacheTxFailover( CacheMode cacheMode, boolean sameAff, final TransactionConcurrency concurrency, final TransactionIsolation isolation) throws Exception { IgniteKernal ignite0 = (IgniteKernal) ignite(0); final AtomicBoolean stop = new AtomicBoolean(); try { ignite0.createCache(cacheConfiguration(CACHE1, cacheMode, 256)); ignite0.createCache(cacheConfiguration(CACHE2, cacheMode, sameAff ? 256 : 128)); final AtomicInteger threadIdx = new AtomicInteger(); IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync( new Callable<Void>() { @Override public Void call() throws Exception { int idx = threadIdx.getAndIncrement(); Ignite ignite = ignite(idx % GRID_CNT); log.info( "Started update thread [node=" + ignite.name() + ", client=" + ignite.configuration().isClientMode() + ']'); IgniteCache<TestKey, TestValue> cache1 = ignite.cache(CACHE1); IgniteCache<TestKey, TestValue> cache2 = ignite.cache(CACHE2); assertNotSame(cache1, cache2); IgniteTransactions txs = ignite.transactions(); ThreadLocalRandom rnd = ThreadLocalRandom.current(); long iter = 0; while (!stop.get()) { boolean sameKey = rnd.nextBoolean(); try { try (Transaction tx = txs.txStart(concurrency, isolation)) { if (sameKey) { TestKey key = new TestKey(rnd.nextLong(KEY_RANGE)); cacheOperation(rnd, cache1, key); cacheOperation(rnd, cache2, key); } else { TestKey key1 = new TestKey(rnd.nextLong(KEY_RANGE)); TestKey key2 = new TestKey(key1.key() + 1); cacheOperation(rnd, cache1, key1); cacheOperation(rnd, cache2, key2); } tx.commit(); } } catch (CacheException | IgniteException e) { log.info("Update error: " + e); } if (iter++ % 500 == 0) log.info("Iteration: " + iter); } return null; } /** * @param rnd Random. * @param cache Cache. * @param key Key. */ private void cacheOperation( ThreadLocalRandom rnd, IgniteCache<TestKey, TestValue> cache, TestKey key) { switch (rnd.nextInt(4)) { case 0: cache.put(key, new TestValue(rnd.nextLong())); break; case 1: cache.remove(key); break; case 2: cache.invoke(key, new TestEntryProcessor(rnd.nextBoolean() ? 1L : null)); break; case 3: cache.get(key); break; default: assert false; } } }, 10, "tx-thread"); long stopTime = System.currentTimeMillis() + 3 * 60_000; long topVer = ignite0.cluster().topologyVersion(); boolean failed = false; while (System.currentTimeMillis() < stopTime) { log.info("Start node."); IgniteKernal ignite = (IgniteKernal) startGrid(GRID_CNT); assertFalse(ignite.configuration().isClientMode()); topVer++; IgniteInternalFuture<?> affFut = ignite .context() .cache() .context() .exchange() .affinityReadyFuture(new AffinityTopologyVersion(topVer)); try { if (affFut != null) affFut.get(30_000); } catch (IgniteFutureTimeoutCheckedException e) { log.error("Failed to wait for affinity future after start: " + topVer); failed = true; break; } Thread.sleep(500); log.info("Stop node."); stopGrid(GRID_CNT); topVer++; affFut = ignite0 .context() .cache() .context() .exchange() .affinityReadyFuture(new AffinityTopologyVersion(topVer)); try { if (affFut != null) affFut.get(30_000); } catch (IgniteFutureTimeoutCheckedException e) { log.error("Failed to wait for affinity future after stop: " + topVer); failed = true; break; } } stop.set(true); fut.get(); assertFalse("Test failed, see log for details.", failed); } finally { stop.set(true); ignite0.destroyCache(CACHE1); ignite0.destroyCache(CACHE2); awaitPartitionMapExchange(); } }