List of usage examples for junit.framework Assert fail
static public void fail(String message)
From source file:de.hybris.platform.test.ThreadPoolTest.java
/** * CORE-66PLA-10816 Potential chance to fetch a PoolableThread with pending transaction from previous run * /*from ww w . jav a 2s .c o m*/ * together with setting logger level for a log4j.logger.de.hybris.platform.util.threadpool=DEBUG prints out * information who/where started the stale transaction */ @Test public void testTransactionCleanUp() throws Exception { final Queue<Transaction> recordedTransactions = new ConcurrentLinkedQueue<Transaction>(); final boolean flagBefore = Config.getBoolean("transaction.monitor.begin", false); Config.setParameter("transaction.monitor.begin", "true"); ThreadPool pool = null; try { // create own pool since we don't want to mess up the system pool = new ThreadPool(Registry.getCurrentTenantNoFallback().getTenantID(), MAX_THREADS); final GenericObjectPool.Config config = new GenericObjectPool.Config(); config.maxActive = MAX_THREADS; config.maxIdle = 1; config.maxWait = -1; config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK; config.testOnBorrow = true; config.testOnReturn = true; config.timeBetweenEvictionRunsMillis = 30 * 1000; // keep idle threads for at most 30 sec pool.setConfig(config); final int maxSize = pool.getMaxActive(); final int activeBefore = pool.getNumActive(); final List<NoClosingTransactionProcess> started = new ArrayList<NoClosingTransactionProcess>(maxSize); for (int i = activeBefore; i < maxSize; i++) { final PoolableThread poolableThread = pool.borrowThread(); final NoClosingTransactionProcess noClosingTransactionProcess = new NoClosingTransactionProcess(); started.add(noClosingTransactionProcess); poolableThread.execute(noClosingTransactionProcess); } Thread.sleep(1000); transacationStartingBarrier.await(); //await for all transacations to start //record all started transactions for (final NoClosingTransactionProcess singleStarted : started) { recordedTransactions.add(singleStarted.getStartedTransaction()); } finishedStaleTransactionLatch.await(180, TimeUnit.SECONDS); Thread.sleep(1000);//give them 1 second to finish final List<HasNoCurrentRunningTransactionProcess> ranAfter = new ArrayList<HasNoCurrentRunningTransactionProcess>( maxSize); Transaction recordedTransaction = recordedTransactions.poll(); do { final PoolableThread poolableThread = pool.borrowThread(); final HasNoCurrentRunningTransactionProcess hasNoCurrentRunningTransactionProcess = new HasNoCurrentRunningTransactionProcess( recordedTransaction); ranAfter.add(hasNoCurrentRunningTransactionProcess); poolableThread.execute(hasNoCurrentRunningTransactionProcess); recordedTransaction = recordedTransactions.poll(); } while (recordedTransaction != null); //still can borrow Assert.assertNotNull(pool.borrowThread()); Thread.sleep(1000); //verify if really Thread had a non started transaction on the enter for (final HasNoCurrentRunningTransactionProcess singleRanAfter : ranAfter) { if (singleRanAfter.getException() != null) { singleRanAfter.getException().printException(); Assert.fail("Some of the thread(s) captured not finshied transaction in the pool "); } } } finally { if (pool != null) { try { pool.close(); } catch (final Exception e) { // can't help it } } Config.setParameter("transaction.monitor.begin", BooleanUtils.toStringTrueFalse(flagBefore)); } }
From source file:com.imaginary.home.cloud.CloudTest.java
private void setupLocation() throws Exception { if (apiKeyId == null) { setupUser();//from ww w. j a v a2s . co m } HashMap<String, Object> lstate = new HashMap<String, Object>(); long key = (System.currentTimeMillis() % 100000); lstate.put("name", "My Home " + key); lstate.put("description", "Integration test location"); lstate.put("timeZone", TimeZone.getDefault().getID()); HttpClient client = getClient(); HttpPost method = new HttpPost(cloudAPI + "/location"); long timestamp = System.currentTimeMillis(); method.addHeader("Content-Type", "application/json"); method.addHeader("x-imaginary-version", VERSION); method.addHeader("x-imaginary-timestamp", String.valueOf(timestamp)); method.addHeader("x-imaginary-api-key", apiKeyId); method.addHeader("x-imaginary-signature", CloudService.sign(apiKeySecret.getBytes("utf-8"), "post:/location:" + apiKeyId + ":" + timestamp + ":" + VERSION)); //noinspection deprecation method.setEntity(new StringEntity((new JSONObject(lstate)).toString(), "application/json", "UTF-8")); HttpResponse response; StatusLine status; try { response = client.execute(method); status = response.getStatusLine(); } catch (IOException e) { e.printStackTrace(); throw new CommunicationException(e); } if (status.getStatusCode() == HttpServletResponse.SC_CREATED) { String json = EntityUtils.toString(response.getEntity()); JSONObject u = new JSONObject(json); locationId = (u.has("locationId") && !u.isNull("locationId")) ? u.getString("locationId") : null; } else { Assert.fail("Failed to create location (" + status.getStatusCode() + ": " + EntityUtils.toString(response.getEntity())); } }
From source file:net.malariagen.gatk.test.WalkerTest.java
/** * execute the test, given the following: * @param name the name of the test//from w ww . j ava 2s . co m * @param args the argument list * @param expectedException the expected exception or null */ public static void executeTest(String name, String args, Class<?> expectedException) { CommandLineGATK instance = new CommandLineGATK(); String[] command = Utils.escapeExpressions(args); // add the logging level to each of the integration test commands // command = Utils.appendArray(command, "-et", ENABLE_REPORTING ? "STANDARD" : "NO_ET"); // run the executable boolean gotAnException = false; try { System.out.println( String.format("Executing test %s with GATK arguments: %s", name, Utils.join(" ", command))); CommandLineExecutable.start(instance, command); } catch (Exception e) { gotAnException = true; if (expectedException != null) { // we expect an exception System.out.println(String.format("Wanted exception %s, saw %s", expectedException, e.getClass())); if (expectedException.isInstance(e)) { // it's the type we expected System.out.println(String.format(" => %s PASSED", name)); } else { e.printStackTrace(); Assert.fail(String.format("Test %s expected exception %s but got %s instead", name, expectedException, e.getClass())); } } else { // we didn't expect an exception but we got one :-( throw new RuntimeException(e); } } // catch failures from the integration test if (expectedException != null) { if (!gotAnException) // we expected an exception but didn't see it Assert.fail(String.format("Test %s expected exception %s but none was thrown", name, expectedException.toString())); } else { if (CommandLineExecutable.result != 0) { throw new RuntimeException("Error running the GATK with arguments: " + args); } } }
From source file:BQJDBC.QueryResultTest.BQForwardOnlyResultSetFunctionTest.java
@Test public void TestResultSetgetFloat() { try {// w w w . j a v a 2s.co m Assert.assertTrue(Result.next()); Assert.assertEquals(new Float(42), BQForwardOnlyResultSetFunctionTest.Result.getFloat(2)); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } }
From source file:BQJDBC.QueryResultTest.BQScrollableResultSetFunctionTest.java
/** * Makes a new Bigquery Connection to URL in file and gives back the * Connection to static con member.//from w w w.j a va 2s .com */ @Before public void NewConnection() { try { if (BQScrollableResultSetFunctionTest.con == null || !BQScrollableResultSetFunctionTest.con.isValid(0)) { this.logger.info("Testing the JDBC driver"); try { Class.forName("net.starschema.clouddb.jdbc.BQDriver"); BQScrollableResultSetFunctionTest.con = DriverManager.getConnection( BQSupportFuncts.constructUrlFromPropertiesFile( BQSupportFuncts.readFromPropFile("installedaccount1.properties")), BQSupportFuncts.readFromPropFile("installedaccount1.properties")); } catch (Exception e) { e.printStackTrace(); this.logger.error("Error in connection" + e.toString()); Assert.fail("General Exception:" + e.toString()); } this.logger.info(((BQConnection) BQScrollableResultSetFunctionTest.con).getURLPART()); } } catch (SQLException e) { logger.debug("Oops something went wrong", e); } this.QueryLoad(); }
From source file:io.fabric8.quickstarts.restdsl.spark.CrmIT.java
/** * HTTP PUT http://localhost:8181/cxf/crm/customerservice/customers is used to upload the contents of * the update_customer.xml file to update the customer information for customer 123. * <p/>//w w w. ja v a 2s .c o m * On the server side, it matches the CustomerService's updateCustomer() method * * @throws Exception */ @Test @Ignore public void putCustomerTest() throws IOException { LOG.info("Sent HTTP PUT request to update customer info"); String inputFile = this.getClass().getResource("/update_customer.xml").getFile(); File input = new File(inputFile); PutMethod put = new PutMethod(CUSTOMER_SERVICE_URL); RequestEntity entity = new FileRequestEntity(input, "application/xml; charset=ISO-8859-1"); put.setRequestEntity(entity); HttpClient httpclient = new HttpClient(); int result = 0; try { result = httpclient.executeMethod(put); LOG.info("Response status code: " + result); LOG.info("Response body: "); LOG.info(put.getResponseBodyAsString()); } catch (IOException e) { LOG.error("Error connecting to {}", CUSTOMER_SERVICE_URL); LOG.error( "You should build the 'rest' quick start and deploy it to a local Fabric8 before running this test"); LOG.error("Please read the README.md file in 'rest' quick start root"); Assert.fail("Connection error"); } finally { // Release current connection to the connection pool once you are // done put.releaseConnection(); } Assert.assertEquals(result, 200); }
From source file:com.mnxfst.testing.server.cfg.TestPTestServerConfigurationParser.java
@Test public void testEvaluateNodeListAndCheckForHandlers() throws ParserConfigurationException, SAXException, IOException, XPathExpressionException { PTestServerConfigurationParser p = new PTestServerConfigurationParser(); Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new ByteArrayInputStream( "<ptest-server><contextHandlers><handler><path>/test</path><class>java.lang.String</class></handler><handler><path>/anotherTest</path><class>java.lang.Integer</class></handler></contextHandlers></ptest-server>" .getBytes())); NodeList result = p.evaluateNodeList(p.xpathExpressionAllHandlerSettings, document); Assert.assertNotNull("The result must not be null", result); Assert.assertEquals("The result length must be 2", 2, result.getLength()); for (int i = 0; i < result.getLength(); i++) { Node node = result.item(i); String path = p.evaluateString(p.xpathExpressionHandlerPath, node); String clazz = p.evaluateString(p.xpathExpressionHandlerClass, node); if (path != null && path.equals("/test")) Assert.assertEquals("The type must be java.lang.String", String.class.getName(), clazz); else if (path != null && path.equals("/anotherTest")) Assert.assertEquals("The type must be java.lang.Integer", Integer.class.getName(), clazz); else// ww w . j a va2s . c om Assert.fail("Invalid path '" + path + "'"); } }
From source file:BQJDBC.QueryResultTest.BQForwardOnlyResultSetFunctionTest.java
@Test public void TestResultSetgetInteger() { try {//from ww w . j a v a2 s.c om Assert.assertTrue(Result.next()); Assert.assertEquals(42, BQForwardOnlyResultSetFunctionTest.Result.getInt(2)); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } }
From source file:BQJDBC.QueryResultTest.Timeouttest.java
@Test public void QueryResultTest06() { final String sql = "SELECT corpus_date,SUM(word_count) FROM publicdata:samples.shakespeare GROUP BY corpus_date ORDER BY corpus_date DESC LIMIT 5;"; final String description = "A query which gets how many words Shapespeare wrote in a year (5 years displayed descending)"; String[][] expectation = new String[][] { { "1612", "1611", "1610", "1609", "1608" }, { "26265", "17593", "26181", "57073", "19846" } }; this.logger.info("Test number: 06"); this.logger.info("Running query:" + sql); java.sql.ResultSet Result = null; try {// w w w . j a v a 2 s . c o m Result = Timeouttest.con.createStatement().executeQuery(sql); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } Assert.assertNotNull(Result); this.logger.debug(description); HelperFunctions.printer(expectation); try { Assert.assertTrue("Comparing failed in the String[][] array", this.comparer(expectation, BQSupportMethods.GetQueryResult(Result))); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail(e.toString()); } }
From source file:BQJDBC.QueryResultTest.QueryResultTest.java
@Test public void QueryResultTest06() { final String sql = "SELECT corpus_date,SUM(word_count) FROM publicdata:samples.shakespeare GROUP BY corpus_date ORDER BY corpus_date DESC LIMIT 5;"; final String description = "A query which gets how many words Shapespeare wrote in a year (5 years displayed descending)"; String[][] expectation = new String[][] { { "1612", "1611", "1610", "1609", "1608" }, { "26265", "17593", "26181", "57073", "19846" } }; this.logger.info("Test number: 06"); this.logger.info("Running query:" + sql); java.sql.ResultSet Result = null; try {/*from ww w. j a v a2 s . c om*/ Result = QueryResultTest.con.createStatement().executeQuery(sql); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } Assert.assertNotNull(Result); this.logger.debug(description); HelperFunctions.printer(expectation); try { Assert.assertTrue("Comparing failed in the String[][] array", this.comparer(expectation, BQSupportMethods.GetQueryResult(Result))); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail(e.toString()); } }