/** @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()); } }
/** * Grabs local events and detects if events was lost since last poll. * * @param ignite Target grid. * @param evtOrderKey Unique key to take last order key from node local map. * @param evtThrottleCntrKey Unique key to take throttle count from node local map. * @param evtTypes Event types to collect. * @param evtMapper Closure to map grid events to Visor data transfer objects. * @return Collections of node events */ public static Collection<VisorGridEvent> collectEvents( Ignite ignite, String evtOrderKey, String evtThrottleCntrKey, final int[] evtTypes, IgniteClosure<Event, VisorGridEvent> evtMapper) { assert ignite != null; assert evtTypes != null && evtTypes.length > 0; ConcurrentMap<String, Long> nl = ignite.cluster().nodeLocalMap(); final long lastOrder = getOrElse(nl, evtOrderKey, -1L); final long throttle = getOrElse(nl, evtThrottleCntrKey, 0L); // When we first time arrive onto a node to get its local events, // we'll grab only last those events that not older than given period to make sure we are // not grabbing GBs of data accidentally. final long notOlderThan = System.currentTimeMillis() - EVENTS_COLLECT_TIME_WINDOW; // Flag for detecting gaps between events. final AtomicBoolean lastFound = new AtomicBoolean(lastOrder < 0); IgnitePredicate<Event> p = new IgnitePredicate<Event>() { /** */ private static final long serialVersionUID = 0L; @Override public boolean apply(Event e) { // Detects that events were lost. if (!lastFound.get() && (lastOrder == e.localOrder())) lastFound.set(true); // Retains events by lastOrder, period and type. return e.localOrder() > lastOrder && e.timestamp() > notOlderThan && F.contains(evtTypes, e.type()); } }; Collection<Event> evts = ignite.events().localQuery(p); // Update latest order in node local, if not empty. if (!evts.isEmpty()) { Event maxEvt = Collections.max(evts, EVTS_ORDER_COMPARATOR); nl.put(evtOrderKey, maxEvt.localOrder()); } // Update throttle counter. if (!lastFound.get()) nl.put(evtThrottleCntrKey, throttle == 0 ? EVENTS_LOST_THROTTLE : throttle - 1); boolean lost = !lastFound.get() && throttle == 0; Collection<VisorGridEvent> res = new ArrayList<>(evts.size() + (lost ? 1 : 0)); if (lost) res.add(new VisorGridEventsLost(ignite.cluster().localNode().id())); for (Event e : evts) { VisorGridEvent visorEvt = evtMapper.apply(e); if (visorEvt != null) res.add(visorEvt); } return res; }