List of usage examples for java.lang InterruptedException toString
public String toString()
From source file:org.kuali.test.runner.execution.TestExecutionContext.java
public void runTest() { try {/*from ww w. jav a 2s . co m*/ startTime = new Date(); poiHelper = new PoiHelper(); poiHelper.writeReportHeader(testSuite, kualiTest); poiHelper.writeColumnHeaders(); if (testSuite != null) { int defaultTestWaitInterval = configuration.getDefaultTestWaitInterval(); for (SuiteTest suiteTest : testSuite.getSuiteTests().getSuiteTestArray()) { KualiTest test = Utils.findKualiTest(configuration, suiteTest.getTestHeader().getPlatformName(), suiteTest.getTestHeader().getTestName()); if (test != null) { // reinitialize new web client for each test initializeHttpClient(); // add pause between tests if configured if (defaultTestWaitInterval > 0) { try { Thread.sleep(defaultTestWaitInterval * 1000); } catch (InterruptedException ex) { LOG.warn(ex.toString(), ex); } } poiHelper.writeTestHeader(test); runTest(new KualiTestWrapper(test), poiHelper); } if (haltTest) { break; } } } else if (kualiTest != null) { runTest(new KualiTestWrapper(kualiTest), poiHelper); } endTime = new Date(); testResultsFile = new File(buildTestReportFileName()); poiHelper.writeFile(testResultsFile); if (performanceData != null) { performanceDataFile = new File(buildPerformanceDataFileName()); writePerformanceDataFile(performanceDataFile); } } finally { cleanup(); completed = true; } }
From source file:org.apache.hadoop.hdfs.TestDatanodeDeath.java
/** * Write to one file, then kill one datanode in the pipeline and then * close the file./* w w w . java 2 s . co m*/ */ private void simpleTest(int datanodeToKill) throws IOException { Configuration conf = new Configuration(); conf.setInt("heartbeat.recheck.interval", 2000); conf.setInt("dfs.heartbeat.interval", 1); conf.setInt("dfs.replication.pending.timeout.sec", 2); conf.setInt("dfs.socket.timeout", 5000); int myMaxNodes = 5; System.out.println("SimpleTest starting with DataNode to Kill " + datanodeToKill); MiniDFSCluster cluster = new MiniDFSCluster(conf, myMaxNodes, true, null); cluster.waitActive(); FileSystem fs = cluster.getFileSystem(); short repl = 3; Path filename = new Path("simpletest.dat"); try { // create a file and write one block of data System.out.println("SimpleTest creating file " + filename); FSDataOutputStream stm = createFile(fs, filename, repl); DFSClient.DFSOutputStream dfstream = (DFSClient.DFSOutputStream) (stm.getWrappedStream()); // these are test settings dfstream.setChunksPerPacket(5); dfstream.setArtificialSlowdown(3000); final long myseed = AppendTestUtil.nextLong(); byte[] buffer = AppendTestUtil.randomBytes(myseed, fileSize); int mid = fileSize / 4; stm.write(buffer, 0, mid); DatanodeInfo[] targets = dfstream.getPipeline(); int count = 5; while (count-- > 0 && targets == null) { try { System.out.println("SimpleTest: Waiting for pipeline to be created."); Thread.sleep(1000); } catch (InterruptedException e) { } targets = dfstream.getPipeline(); } if (targets == null) { int victim = AppendTestUtil.nextInt(myMaxNodes); System.out.println("SimpleTest stopping datanode random " + victim); cluster.stopDataNode(victim); } else { int victim = datanodeToKill; System.out.println("SimpleTest stopping datanode " + targets[victim].getName()); cluster.stopDataNode(targets[victim].getName()); } System.out.println("SimpleTest stopping datanode complete"); // write some more data to file, close and verify stm.write(buffer, mid, fileSize - mid); stm.close(); checkFile(fs, filename, repl, numBlocks, fileSize, myseed); } catch (Throwable e) { System.out.println("Simple Workload exception " + e); e.printStackTrace(); assertTrue(e.toString(), false); } finally { fs.close(); cluster.shutdown(); } }
From source file:org.jahia.test.services.templates.ModuleDeploymentTest.java
@Test public void testJarUndeploy() throws RepositoryException { JCRTemplate.getInstance().doExecuteWithSystemSession(new JCRCallback<Object>() { @Override/* w ww . ja v a2 s. co m*/ public Object doInJCR(JCRSessionWrapper session) throws RepositoryException { try { File tmpFile = File.createTempFile("module", ".jar"); InputStream stream = managerService.getTemplatePackageById("jahia-test-module") .getResource("dummy1-" + "1.0" + ".jar").getInputStream(); FileUtils.copyInputStreamToFile(stream, tmpFile); JahiaTemplatesPackage pack = managerService.deployModule(tmpFile, session); tmpFile.delete(); try { Thread.sleep(500); } catch (InterruptedException e) { logger.error(e.getMessage(), e); } managerService.undeployModule(pack); pack = managerService.getTemplatePackageById("dummy1"); assertNull(pack); assertFalse("Action not unregistered", managerService.getActions().containsKey("my-post-action")); // try { // NodeTypeRegistry.getInstance().getNodeType("jnt:testComponent1"); // fail("Definition not unregistered"); // } catch (NoSuchNodeTypeException e) { // } assertTrue("Module view is not correctly unregistered", managerService.getModulesWithViewsForComponent("jnt:testComponent1").isEmpty()); } catch (IOException e) { logger.error(e.getMessage(), e); fail(e.toString()); } return null; } }); }
From source file:com.fluidops.iwb.deepzoom.CXMLServlet.java
@SuppressWarnings(value = "DM_CONVERT_CASE", justification = "checked") private void renderCollection(Map<URI, Map<URI, Set<Value>>> graph, Vector<URI> predicates, HashMap<URI, Integer> facetCountMap, String collection, String collectionName, PrintStream httpOut, String q, HttpServletRequest req, int maxEntities, int maxFacets) throws FileNotFoundException, IOException { PrintStream resultCache = new PrintStream(new FileOutputStream(getCacheFile("resultCache", hash(q))), false, "UTF-8"); PrintStream out = new PrintStream(new DualOutputStream(httpOut, resultCache), false, "UTF-8"); out.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); //out.println("<?xml-stylesheet type=\"text/xsl\" href=\"/int/pivot/pivot.xsl\"?>"); out.println("<Collection Name=\"" + XML.escape(collectionName) + "\" SchemaVersion=\"1.0\""); out.println(" xmlns=\"http://schemas.microsoft.com/collection/metadata/2009\""); out.println(" xmlns:p=\"http://schemas.microsoft.com/livelabs/pivot/collection/2009\""); out.println(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""); out.println(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">"); Dimension d = new Dimension(200, 200); Writer collectionWriter = null; try {/*from w ww .j a va 2s. c o m*/ collectionWriter = new OutputStreamWriter( new FileOutputStream(getCacheFile("collectionCache", hash(q))), "UTF-8"); } catch (IOException e) { logger.warn(e.getMessage()); } collectionWriter.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<Collection MaxLevel=\"8\" TileSize=\"256\" Format=\"jpg\" NextItemId=\"1001\" ServerFormat=\"Default\" xmlns=\"http://schemas.microsoft.com/deepzoom/2009\">\n" + "<Items>\n"); // render facet categories out.println("<FacetCategories>"); List<URI> displayedFacets = new LinkedList<URI>(); // We limit the number of displayed facets (maxPivotFacets) // We rank facets by the number of entities that have a value for the given facet // The ranking only needs to be performed if maxFacets>0 (0 disables limitation) // and the number of facets is actually greater than maxFacets if (facetCountMap != null && maxFacets > 0 && facetCountMap.size() > maxFacets) { Set<Entry<URI, Integer>> s = facetCountMap.entrySet(); for (int i = 0; i < maxFacets; i++) { int max = 0; Entry<URI, Integer> maxEntry = null; for (Entry<URI, Integer> e : s) { if (e.getValue() > max) { maxEntry = e; max = e.getValue(); } } if (maxEntry == null) break; displayedFacets.add(maxEntry.getKey()); s.remove(maxEntry); } } else displayedFacets = predicates; Vector<URI> facetNames = new Vector<URI>(); Vector<String> facetLabels = new Vector<String>(); // we may use any sort order here; currently, we sort alphabetically, // with the exception that the type facet is always on top Collections.sort(predicates, new Comparator<URI>() { public int compare(URI o1, URI o2) { if (o1.equals(RDF.TYPE)) return -1; else if (o2.equals(RDF.TYPE)) return 1; else return o1.stringValue().compareTo(o2.stringValue()); } }); for (URI predicate : predicates) { ReadDataManager dm = EndpointImpl.api().getDataManager(); if (dm.getLabel(predicate).equals("name") || facetNames.contains(predicate)) continue; // labels of names are unfortunately not unique, but must not occur as duplicates facetNames.add(predicate); if (displayedFacets.contains(predicate)) { String name = dm.getLabel(predicate); name = escape(name).trim(); // TODO: only quick fix, has to be handled properly // facet labels need to be unique, disregarding capitalization if (!facetLabels.contains(name.toLowerCase())) { facetLabels.add(name.toLowerCase()); String type; URI range = predicateTypes.get(predicate); if (range == null) range = XMLSchema.STRING; if (range.equals(XMLSchema.DATETIME) || range.equals(XMLSchema.DATE)) type = "DateTime"; else if (range.equals(XMLSchema.FLOAT) || range.equals(XMLSchema.DOUBLE) || range.equals(XMLSchema.INT) || range.equals(XMLSchema.INTEGER) || range.equals(XMLSchema.LONG)) type = "Number"; else type = "String"; //default out.println("<FacetCategory Name=\"" + XML.escape(name) + "\" Type=\"" + type + "\" p:IsFilterVisible=\"true\" p:IsMetaDataVisible=\"false\" />"); out.println("<FacetCategory Name=\"" + XML.escape(name) + ":\" Type=\"Link\" p:IsFilterVisible=\"false\" p:IsMetaDataVisible=\"true\" />"); } } } out.println( "<FacetCategory Name=\"Home\" Type=\"Link\" p:IsFilterVisible=\"false\" p:IsMetaDataVisible=\"true\" />"); out.println("</FacetCategories>"); // render items in collection String collectionID = "collection" + hash(q) + ".xml"; out.println("<Items ImgBase=\"" + collection + "/" + collectionID + "\">"); int counter = 0; Vector<String> imageVector = new Vector<String>(); // queryImageVector.put(hash(q), imageVector); ImageLoader loader = new ImageLoader(api().getRequestMapper().getInternalUrlWithoutContext(req)); for (Entry<URI, Map<URI, Set<Value>>> entry : graph.entrySet()) { Resource entity = entry.getKey(); if (counter >= maxEntities) break; Map<URI, Set<Value>> facets = entry.getValue(); // We assume that all entities are URIs. Perhaps need to re-evaluate this assumption URI uri = (URI) entity; String img = null; if (IWBCmsUtil.isUploadedFile(uri) && ImageResolver.isImage(uri.stringValue())) img = getImageURLForValue(uri); else { // verify if there is an image in the facets using image properties // given by ImageResolver (e.g. foaf:img) for (URI imageProperty : ImageResolver.getDefaultImageResolver().getImageProperties()) { Set<Value> imgForProperty = facets.get(imageProperty); if (imgForProperty != null && imgForProperty.size() > 0) { img = getImageURLForValue(imgForProperty.iterator().next()); break; // found an image } } // fallback, no image found: indicates that ID card should be generated if (img == null) img = "id:" + entity.stringValue() + ".jpg"; } String filename = ImageLoader.filename(img); if (!imageVector.contains(img)) //only need to load the image once { loader.createImageThreaded(uri, facets, img, collection); imageVector.add(img); int imgID = imageVector.indexOf(img); collectionWriter.write("<I Id=\"" + imgID + "\" N=\"" + imgID + "\" Source=\"dzimages/" + ImageLoader.subdir(filename) + "/" + ((filename.lastIndexOf(".") > -1) ? filename.substring(0, filename.lastIndexOf(".")) : filename) + ".xml\">" + "<Size Width=\"" + d.width + "\" Height=\"" + d.height + "\"/></I>"); } int imgID = imageVector.indexOf(img); ReadDataManager dm = EndpointImpl.api().getDataManager(); String label = cleanLabel(dm.getLabel(uri)); if (label.length() == 0) continue; out.println("<Item Img=\"#" + imgID + "\" Id=\"" + counter + "\" Href=\"" + EndpointImpl.api().getRequestMapper().getRequestStringFromValue(uri) + "\" Name=\"" + label + "\">"); String facetString = "";// temp string as we do not know whether there are any facet values for (Entry<URI, Set<Value>> facetEntry : facets.entrySet()) { URI predicate = facetEntry.getKey(); if (predicate.equals(Vocabulary.DBPEDIA_ONT.THUMBNAIL)) continue; String name = dm.getLabel(predicate); if (name.equals("name")) continue; Set<Value> facetValues = facetEntry.getValue(); String values = ""; String exploreValues = ""; int facetValueCounter = 0; for (Value value : facetValues) { if (value == null) continue; if (facetValueCounter++ > 1000) break; //TODO: temp hack to prevent scalability problems, improve logic label = cleanLabel(dm.getLabel(value)); if (label.equals("")) continue; String href = EndpointImpl.api().getRequestMapper().getRequestStringFromValue(value); if ((value instanceof Literal) && !Config.getConfig().getLinkLiterals()) { href = "#"; } if (label.toLowerCase().startsWith("category:")) { label = label.substring(9); } URI range = predicateTypes.get(predicate); if (range == null) values += "<String Value=\"" + label + "\"/>"; else if (range.equals(XMLSchema.FLOAT) || range.equals(XMLSchema.DOUBLE) || range.equals(XMLSchema.INT) || range.equals(XMLSchema.INTEGER) || range.equals(XMLSchema.LONG)) { try { // Need to be compliant with xsd:decimal values += "<Number Value=\"" + (new BigDecimal(Double.parseDouble(label))).toPlainString() + "\"/>"; } catch (Exception e) { logger.warn("Parsing problem with: " + label); } } else if (range.equals(XMLSchema.DATETIME) || range.equals(XMLSchema.DATE)) { Date date = null; // Loop over supported date formats for (DateFormat formatter : formatters) { try { date = (Date) formatter.parse(label); break; } // If date format is not supported.. catch (ParseException e) { logger.debug("Date format not supported: " + label + ". Using today instead."); } } if (date != null) { DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); values += "<DateTime Value=\"" + format.format(date) + "\"/>"; } } else values += "<String Value=\"" + label + "\"/>"; exploreValues += "<Link Href=\"" + href + "\" Name=\"" + label + "\"/>"; } name = escape(name).trim(); // values = values.replace("]", ""); if (values.length() > 0 && displayedFacets.contains(predicate)) facetString += "<Facet Name=\"" + XML.escape(name) + "\">" + values + "</Facet>"; if (exploreValues.length() > 0 && displayedFacets.contains(predicate)) facetString += "<Facet Name=\"" + XML.escape(name) + ":\">" + exploreValues + "</Facet>"; } /* //Query for related elements, currently not used String href = "CONSTRUCT { ?uri <http://dbpedia.org/ontology/thumbnail> ?img . ?uri ?p ?o . } WHERE { { ?uri ?relationship <"+uri.stringValue()+"> } UNION { <"+uri.stringValue()+"> ?relationship ?uri } . ?uri <http://dbpedia.org/ontology/thumbnail> ?img . ?uri ?p ?o }"; try { href=URLEncoder.encode(href, "UTF-8"); } catch (UnsupportedEncodingException e) { logger.error(e.getMessage(), e); } facetString+="<Facet Name=\"Related\"><Link Href=\"query.cxml?q="+href+"\" Name=\"Explore Related\"/></Facet>"; */ if (!facetString.isEmpty()) out.println("<Facets>" + facetString + "</Facets>"); out.println("</Item>"); counter++; } if (counter == 0) { // should show some image indicating that nothing has been found, for now we just show a text out.println("<Item Img=\"#0\" Id=\"0\" Name=\"Nothing found\">"); out.println("</Item>"); URI uri = ValueFactoryImpl.getInstance().createURI("http://www.fluidops.com/Nothing Found"); // id: indicates that ID card should be generated String img = "id:" + uri.stringValue() + ".jpg"; String filename = ImageLoader.filename(img); Map<URI, Set<Value>> facets = new HashMap<URI, Set<Value>>(); loader.createImageThreaded(uri, facets, img, collection); imageVector.add(img); int imgID = 0; collectionWriter.write("<I Id=\"" + imgID + "\" N=\"" + imgID + "\" Source=\"dzimages/" + ImageLoader.subdir(filename) + "/" + ((filename.lastIndexOf(".") > -1) ? filename.substring(0, filename.lastIndexOf(".")) : filename) + ".xml\">" + "<Size Width=\"" + d.width + "\" Height=\"" + d.height + "\"/></I>"); } try { writeImageListToFile("imageCache", hash(q), imageVector); } catch (IOException e) { logger.warn(e.getMessage(), e); } // We wait until all image loading threads have finished, but at most one minute long wait = 0; while (loader.threadCounter > 0 && wait < 60000) { try { Thread.sleep(10); wait += 10; } catch (InterruptedException e1) { logger.debug(e1.toString()); } } collectionWriter.write("</Items>\n</Collection>"); collectionWriter.close(); out.println("</Items>"); out.println("</Collection>"); out.close(); }
From source file:org.medcare.Dicom.DicomActivity.java
public boolean sendRemotes(String arg) { if (connection == null) { Log.d(TAG, "sendRemotes Please Login First"); return false; }//from w ww.j ava 2 s. c o m Log.d(TAG, "sendRemotes " + arg); String to = getXmppRemoteUser(); Message msg = new Message(to, Message.Type.chat); msg.setBody(arg); sendRemotesTime = Calendar.getInstance().getTimeInMillis(); //To avoid xmpp account to be blocked if ((lastSendRemotesTime > 0) && ((sendRemotesTime - lastSendRemotesTime) < XMPP_GAP)) { try { Thread.sleep(1000 - (sendRemotesTime - lastSendRemotesTime)); } catch (InterruptedException e) { Log.e(TAG, e.toString()); } } Log.i("NOMBRE", "Sending text [" + arg + "] to [" + to + "]"); connection.sendPacket(msg); lastSendRemotesTime = sendRemotesTime; return true; }
From source file:org.cerberus.serviceEngine.impl.SeleniumService.java
@Override public MessageEvent doSeleniumActionMouseOverAndWait(Selenium selenium, String actionObject, String actionProperty) {// ww w. j a v a 2 s . c o m MessageEvent message; try { if (!StringUtil.isNull(actionProperty) && !StringUtil.isNull(actionObject)) { if (StringUtil.isNumeric(actionProperty)) { try { Actions actions = new Actions(selenium.getDriver()); WebElement menuHoverLink = this.getSeleniumElement(selenium, actionObject, true); actions.moveToElement(menuHoverLink); actions.build().perform(); int sleep = Integer.parseInt(actionProperty); try { Thread.sleep(sleep); message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_MOUSEOVERANDWAIT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", actionObject)); message.setDescription( message.getDescription().replaceAll("%TIME%", Integer.toString(sleep))); return message; } catch (InterruptedException e) { MyLogger.log(SeleniumService.class.getName(), Level.INFO, e.toString()); message = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVERANDWAIT); message.setDescription(message.getDescription().replaceAll("%ELEMENT1%", actionObject)); message.setDescription( message.getDescription().replaceAll("%TIME%", Integer.toString(sleep))); return message; } } catch (NoSuchElementException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVER_NO_SUCH_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", actionObject)); MyLogger.log(SeleniumService.class.getName(), Level.ERROR, exception.toString()); return message; } } message = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVERANDWAIT_NO_NUMERIC); message.setDescription(message.getDescription().replaceAll("%TIME%", actionProperty)); return message; } else if (StringUtil.isNull(actionProperty) && !StringUtil.isNull(actionObject)) { try { Actions actions = new Actions(selenium.getDriver()); WebElement menuHoverLink = this.getSeleniumElement(selenium, actionObject, true); actions.moveToElement(menuHoverLink); actions.build().perform(); } catch (NoSuchElementException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVER_NO_SUCH_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", actionObject)); MyLogger.log(SeleniumService.class.getName(), Level.ERROR, exception.toString()); return message; } message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLICKANDNOWAIT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", actionObject)); return message; } } catch (WebDriverException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELENIUM_CONNECTIVITY); MyLogger.log(SeleniumService.class.getName(), Level.FATAL, exception.toString()); return message; } return new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVERANDWAIT_GENERIC); }
From source file:org.cerberus.serviceEngine.impl.SeleniumService.java
@Override public MessageEvent doSeleniumActionClickWait(Selenium selenium, String actionObject, String actionProperty) { MessageEvent message;/* ww w .ja va 2s . c om*/ try { if (!StringUtil.isNull(actionProperty) && !StringUtil.isNull(actionObject)) { try { this.getSeleniumElement(selenium, actionObject, true).click(); } catch (NoSuchElementException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CLICK_NO_SUCH_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", actionObject)); MyLogger.log(SeleniumService.class.getName(), Level.ERROR, exception.toString()); return message; } if (StringUtil.isNumeric(actionProperty)) { int sleep = Integer.parseInt(actionProperty); try { Thread.sleep(sleep); message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLICKANDWAIT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", actionObject)); message.setDescription( message.getDescription().replaceAll("%TIME%", Integer.toString(sleep))); return message; } catch (InterruptedException e) { MyLogger.log(SeleniumService.class.getName(), Level.INFO, e.toString()); message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CLICKANDWAIT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", actionObject)); message.setDescription( message.getDescription().replaceAll("%TIME%", Integer.toString(sleep))); return message; } } message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CLICKANDWAIT_NO_NUMERIC); message.setDescription(message.getDescription().replaceAll("%TIME%", actionProperty)); return message; } else if (StringUtil.isNull(actionProperty) && !StringUtil.isNull(actionObject)) { try { this.getSeleniumElement(selenium, actionObject, true).click(); } catch (NoSuchElementException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CLICK_NO_SUCH_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", actionObject)); MyLogger.log(SeleniumService.class.getName(), Level.ERROR, exception.toString()); return message; } message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLICKANDNOWAIT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", actionObject)); return message; } else if (!StringUtil.isNull(actionProperty) && StringUtil.isNull(actionObject)) { try { this.getSeleniumElement(selenium, actionProperty, true).click(); } catch (NoSuchElementException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CLICK_NO_SUCH_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", actionProperty)); MyLogger.log(SeleniumService.class.getName(), Level.ERROR, exception.toString()); return message; } message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLICKANDNOWAIT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", actionProperty)); return message; } } catch (WebDriverException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELENIUM_CONNECTIVITY); MyLogger.log(SeleniumService.class.getName(), Level.FATAL, exception.toString()); return message; } return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLICKANDWAIT_GENERIC); }
From source file:org.lsc.AbstractSynchronize.java
public void run() { counter = new InfoCounter(); SynchronizeThreadPoolExecutor threadPool = new SynchronizeThreadPoolExecutor( abstractSynchronize.getThreads()); Entry<String, LscDatasets> nextId = null; try {/* w ww .j a v a 2 s. co m*/ IAsynchronousService aService = null; boolean fromSource = true; if (task.getDestinationService() instanceof IAsynchronousService) { aService = (IAsynchronousService) task.getDestinationService(); fromSource = false; } else if (task.getSourceService() instanceof IAsynchronousService) { aService = (IAsynchronousService) task.getSourceService(); } else { LOGGER.error( "LSC should never reach this point! Please consider debugging the code because we are trying to launch an asynchronous sync without any asynchronous service!"); return; } AbstractSynchronize.LOGGER.debug("Asynchronous synchronize {}", task.getName()); boolean interrupted = false; while (!interrupted) { nextId = aService.getNextId(); if (nextId != null) { threadPool.runTask(new SynchronizeTask(task, counter, abstractSynchronize, nextId, fromSource)); } else { try { Thread.sleep(aService.getInterval()); } catch (InterruptedException e) { AbstractSynchronize.LOGGER.debug("Synchronization thread interrupted !"); interrupted = true; } } } } catch (LscServiceException e) { counter.incrementCountError(); abstractSynchronize.logActionError(null, nextId, e); } try { threadPool.shutdown(); threadPool.awaitTermination(abstractSynchronize.getTimeLimit(), TimeUnit.SECONDS); } catch (InterruptedException e) { LOGGER.error("Tasks terminated according to time limit: " + e.toString(), e); LOGGER.info("If you want to avoid this message, " + "increase the time limit by using dedicated parameter."); } }
From source file:org.cerberus.serviceEngine.impl.SeleniumService.java
@Override public MessageEvent doSeleniumActionWait(Selenium selenium, String object, String property) { MessageEvent message;//from w w w .j a va 2 s . c om try { if (!StringUtil.isNull(property)) { if (StringUtil.isNumeric(property)) { try { Thread.sleep(Integer.parseInt(property)); } catch (InterruptedException exception) { MyLogger.log(SeleniumService.class.getName(), Level.INFO, exception.toString()); message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT); message.setDescription(message.getDescription().replaceAll("%TIME%", property)); return message; } message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_TIME); message.setDescription(message.getDescription().replaceAll("%TIME%", property)); return message; } else { try { WebDriverWait wait = new WebDriverWait(selenium.getDriver(), TIMEOUT_WEBELEMENT); wait.until(ExpectedConditions.presenceOfElementLocated(this.getIdentifier(property))); message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", property)); return message; } catch (NoSuchElementException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT_NO_SUCH_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", property)); MyLogger.log(SeleniumService.class.getName(), Level.ERROR, exception.toString()); return message; } } } else if (!StringUtil.isNull(object)) { if (StringUtil.isNumeric(object)) { try { Thread.sleep(Integer.parseInt(object)); } catch (InterruptedException exception) { MyLogger.log(SeleniumService.class.getName(), Level.INFO, exception.toString()); message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT); message.setDescription(message.getDescription().replaceAll("%TIME%", object)); return message; } message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_TIME); message.setDescription(message.getDescription().replaceAll("%TIME%", object)); return message; } else { try { WebDriverWait wait = new WebDriverWait(selenium.getDriver(), TIMEOUT_WEBELEMENT); wait.until(ExpectedConditions.presenceOfElementLocated(this.getIdentifier(object))); message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", object)); return message; } catch (NoSuchElementException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT_NO_SUCH_ELEMENT); message.setDescription(message.getDescription().replaceAll("%ELEMENT%", object)); MyLogger.log(SeleniumService.class.getName(), Level.ERROR, exception.toString()); return message; } } } else { try { Thread.sleep(TIMEOUT_MILLIS); } catch (InterruptedException exception) { MyLogger.log(SeleniumService.class.getName(), Level.INFO, exception.toString()); message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT); message.setDescription( message.getDescription().replaceAll("%TIME%", Integer.toString(TIMEOUT_MILLIS))); return message; } message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_TIME); message.setDescription( message.getDescription().replaceAll("%TIME%", Integer.toString(TIMEOUT_MILLIS))); return message; } } catch (WebDriverException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELENIUM_CONNECTIVITY); MyLogger.log(SeleniumService.class.getName(), Level.FATAL, exception.toString()); return message; } }
From source file:com.chinamobile.bcbsp.client.BSPJobClient.java
/** * Submit a new job to run./*from w ww . j av a2 s.c o m*/ * @param job BSPJob * @return Review comments: (1)The content of submitJobDir is decided by the * client. I think it is dangerous because two different clients maybe * generate the same submitJobDir. Review time: 2011-11-30; Reviewer: * Hongxu Zhang. Fix log: (1)In order to avoid the conflict, I use the * jobId to generate the submitJobDir. Because the jobId is unique so * this problem can be solved. Fix time: 2011-12-04; Programmer: * Zhigang Wang. Review comments: (2)There, the client must submit * relative information about the job. There maybe some exceptions * during this process. When exceptions occur, this job should not be * executed and the relative submitJobDir must be cleanup. Review * time: 2011-12-04; Reviewer: Hongxu Zhang. Fix log: (2)The process * of submiting files has been surrounded by try-catch. The * submitJobDir will be cleanup in the catch process. Fix time: * 2011-12-04; Programmer: Zhigang Wang. */ public RunningJob submitJobInternal(BSPJob job) { BSPJobID jobId = null; Path submitJobDir = null; try { jobId = jobSubmitClient.getNewJobId(); submitJobDir = new Path(getSystemDir(), "submit_" + jobId.toString()); Path submitJarFile = null; LOG.info("debug: job type is " + job.getJobType()); if (Constants.USER_BC_BSP_JOB_TYPE_C.equals(job.getJobType())) { submitJarFile = new Path(submitJobDir, "jobC"); LOG.info("debug:" + submitJarFile.toString()); } else { LOG.info("debug: before submitJarFile = new " + "Path(submitJobDir,job.jar);"); submitJarFile = new Path(submitJobDir, "job.jar"); LOG.info("debug:" + submitJarFile.toString()); } Path submitJobFile = new Path(submitJobDir, "job.xml"); Path submitSplitFile = new Path(submitJobDir, "job.split"); // set this user's id in job configuration, so later job files can // be accessed using this user's id UnixUserGroupInformation ugi = getUGI(job.getConf()); // Create a number of filenames in the BSPController's fs namespace FileSystem files = getFs(); files.delete(submitJobDir, true); submitJobDir = files.makeQualified(submitJobDir); submitJobDir = new Path(submitJobDir.toUri().getPath()); BSPFsPermission bspSysPerms = new BSPFspermissionImpl(2); FileSystem.mkdirs(files, submitJobDir, bspSysPerms.getFp()); files.mkdirs(submitJobDir); short replication = (short) job.getInt("bsp.submit.replication", 10); String originalJarPath = null; LOG.info("debug: job type is " + job.getJobType()); if (Constants.USER_BC_BSP_JOB_TYPE_C.equals(job.getJobType())) { LOG.info("debug: originalJarPath = job.getJobExe();" + job.getJobExe()); originalJarPath = job.getJobExe(); LOG.info("debug:" + submitJarFile.toString()); job.setJobExe(submitJarFile.toString()); } else { LOG.info("debug: jar"); originalJarPath = job.getJar(); job.setJar(submitJarFile.toString()); } if (originalJarPath != null) { // copy jar to BSPController's fs // use jar name if job is not named. if ("".equals(job.getJobName())) { job.setJobName(new Path(originalJarPath).getName()); } // job.setJar(submitJarFile.toString()); fs.copyFromLocalFile(new Path(originalJarPath), submitJarFile); fs.setReplication(submitJarFile, replication); fs.setPermission(submitJarFile, new BSPFspermissionImpl(0).getFp()); } else { LOG.warn("No job jar file set. User classes may not be found. " + "See BSPJob#setJar(String) or check Your jar file."); } // Set the user's name and working directory job.setUser(ugi.getUserName()); if (ugi.getGroupNames().length > 0) { job.set("group.name", ugi.getGroupNames()[0]); } if (new BSPHdfsImpl().getWorkingDirectory() == null) { job.setWorkingDirectory(fs.getWorkingDirectory()); } int maxClusterStaffs = jobSubmitClient.getClusterStatus(false).getMaxClusterStaffs(); if (job.getNumPartition() == 0) { job.setNumPartition(maxClusterStaffs); } if (job.getNumPartition() > maxClusterStaffs) { job.setNumPartition(maxClusterStaffs); } job.setNumBspStaff(job.getNumPartition()); int splitNum = 0; splitNum = writeSplits(job, submitSplitFile); if (splitNum > job.getNumPartition() && splitNum <= maxClusterStaffs) { job.setNumPartition(splitNum); job.setNumBspStaff(job.getNumPartition()); } if (splitNum > maxClusterStaffs) { LOG.error("Sorry, the number of files is more than maxClusterStaffs:" + maxClusterStaffs); throw new IOException("Could not launch job"); } job.set(Constants.USER_BC_BSP_JOB_SPLIT_FILE, submitSplitFile.toString()); LOG.info("[Max Staff Number] " + maxClusterStaffs); LOG.info("The number of splits for the job is: " + splitNum); LOG.info("The number of staffs for the job is: " + job.getNumBspStaff()); BSPFSDataOutputStream bspout = new BSPFSDataOutputStreamImpl(fs, submitJobFile, new BSPFspermissionImpl(0).getFp()); try { job.writeXml(bspout.getOut()); } finally { bspout.close(); } // Now, actually submit the job (using the submit name) JobStatus status = jobSubmitClient.submitJob(jobId, submitJobFile.toString()); if (status != null) { return new NetworkedJob(status); } else { throw new IOException("Could not launch job"); } } catch (FileNotFoundException fnfE) { LOG.error("Exception has been catched in BSPJobClient--submitJobInternal !", fnfE); Fault f = new Fault(Fault.Type.SYSTEMSERVICE, Fault.Level.INDETERMINATE, "null", fnfE.toString()); jobSubmitClient.recordFault(f); jobSubmitClient.recovery(jobId); try { FileSystem files = getFs(); files.delete(submitJobDir, true); } catch (IOException e) { //LOG.error("Failed to cleanup the submitJobDir:" + submitJobDir); throw new RuntimeException("Failed to cleanup the submitJobDir", e); } return null; } catch (ClassNotFoundException cnfE) { LOG.error("Exception has been catched in BSPJobClient--submitJobInternal !", cnfE); Fault f = new Fault(Fault.Type.SYSTEMSERVICE, Fault.Level.WARNING, "null", cnfE.toString()); jobSubmitClient.recordFault(f); jobSubmitClient.recovery(jobId); try { FileSystem files = getFs(); files.delete(submitJobDir, true); } catch (IOException e) { //LOG.error("Failed to cleanup the submitJobDir:" + submitJobDir); throw new RuntimeException("Failed to cleanup the submitJobDir", e); } return null; } catch (InterruptedException iE) { LOG.error("Exception has been catched in BSPJobClient--submitJobInternal !", iE); Fault f = new Fault(Fault.Type.SYSTEMSERVICE, Fault.Level.CRITICAL, "null", iE.toString()); jobSubmitClient.recordFault(f); jobSubmitClient.recovery(jobId); try { FileSystem files = getFs(); files.delete(submitJobDir, true); } catch (IOException e) { //LOG.error("Failed to cleanup the submitJobDir:" + submitJobDir); throw new RuntimeException("Failed to cleanup the submitJobDir", e); } return null; } catch (Exception ioE) { LOG.error("Exception has been catched in BSPJobClient--submitJobInternal !", ioE); Fault f = new Fault(Fault.Type.DISK, Fault.Level.CRITICAL, "null", ioE.toString()); jobSubmitClient.recordFault(f); jobSubmitClient.recovery(jobId); try { FileSystem files = getFs(); files.delete(submitJobDir, true); } catch (IOException e) { //LOG.error("Failed to cleanup the submitJobDir:" + submitJobDir); throw new RuntimeException("Failed to cleanup the submitJobDir", e); } return null; } }