@Test public void test() { System.out.println("CNF: " + cnf + "\n" + "Expectations: " + expectations); for (Expectation expectation : expectations) { expectation.examine(skipper); } }
public static void assertTrue(long timeout, Iterable<Expectation> expectations) throws Exception { long start = System.currentTimeMillis(); while (true) { List<Expectation> failures = new ArrayList<Expectation>(); for (Expectation expectation : expectations) { if (!expectation.isValid()) { failures.add(expectation); } } if (failures.isEmpty()) { return; } long now = System.currentTimeMillis(); long elapsed = now - start; if (elapsed < timeout) { try { Thread.sleep(1000); } catch (InterruptedException e) { // ignore } } else { String message = failures.toString(); fail(message + ". Failed after " + elapsed + " millis"); } } }
public void testGetType() throws Exception { final StringTextSource textSource = new StringTextSource(""); final Expectation[] wordsOfExpectation = { new Expectation(Buffer.HTML_BUFFER, "somefile/blah.htm"), new Expectation(Buffer.HTML_BUFFER, "foo.html"), new Expectation(Buffer.JAVA_BUFFER, "eieio.java"), new Expectation(Buffer.MSDOS_BATCH_BUFFER, "eat/my.shorts.bat"), new Expectation(Buffer.MSDOS_BATCH_BUFFER, "alpha.cmd"), new Expectation(Buffer.PROPERTIES_BUFFER, "essential.properties"), new Expectation(Buffer.PYTHON_BUFFER, "why/oh.py"), new Expectation(Buffer.SHELL_BUFFER, "bishbosh.bash"), new Expectation(Buffer.SHELL_BUFFER, "clishclosh.csh"), new Expectation(Buffer.SHELL_BUFFER, "kkkkrassh.ksh"), new Expectation(Buffer.SHELL_BUFFER, "be/quiet.sh"), new Expectation(Buffer.TEXT_BUFFER, "tick.txt"), new Expectation(Buffer.TEXT_BUFFER, "tech.text"), new Expectation(Buffer.XML_BUFFER, "xplicitly.xml"), new Expectation(Buffer.UNKNOWN_BUFFER, "blurb/blah"), new Expectation(Buffer.UNKNOWN_BUFFER, "fidledly.foo"), new Expectation(Buffer.UNKNOWN_BUFFER, "bah/bah"), new Expectation(Buffer.UNKNOWN_BUFFER, "...."), }; for (int i = 0; i < wordsOfExpectation.length; ++i) { final Expectation expectation = wordsOfExpectation[i]; final Buffer buffer = new BufferImplementation(s_resources, textSource, expectation.getFile()); assertEquals(expectation.getType(), buffer.getType()); assertEquals(textSource, buffer.getTextSource()); } assertEquals(Buffer.HTML_BUFFER, Buffer.HTML_BUFFER); AssertUtilities.assertNotEquals(Buffer.HTML_BUFFER, Buffer.TEXT_BUFFER); AssertUtilities.assertNotEquals(Buffer.TEXT_BUFFER, Buffer.HTML_BUFFER); AssertUtilities.assertNotEquals(Buffer.PROPERTIES_BUFFER, Buffer.UNKNOWN_BUFFER); assertEquals(Buffer.PYTHON_BUFFER, Buffer.PYTHON_BUFFER); }
protected VoltTable[] executeQueriesInABatch(List<QueuedSQL> batch, boolean isFinalSQL) { final int batchSize = batch.size(); VoltTable[] results = null; if (batchSize == 0) { return new VoltTable[] {}; } // IF THIS IS HSQL, RUN THE QUERIES DIRECTLY IN HSQL if (getHsqlBackendIfExists() != null) { results = new VoltTable[batchSize]; int i = 0; for (QueuedSQL qs : batch) { List<StmtParameter> sparams; if (qs.stmt.catStmt != null) { CatalogMap<StmtParameter> sparamsMap = qs.stmt.catStmt.getParameters(); sparams = CatalogUtil.getSortedCatalogItems(sparamsMap, "index"); } else { assert (qs.stmt.plan != null); // TODO: For now extracted ad hoc SQL parameters are discarded qs.params = new ParameterSet(); sparams = new ArrayList<StmtParameter>(); } results[i++] = getHsqlBackendIfExists().runSQLWithSubstitutions(qs.stmt, qs.params, sparams); } } else if (m_catProc.getSinglepartition()) { results = fastPath(batch); } else { results = slowPath(batch, isFinalSQL); } // check expectations int i = 0; for (QueuedSQL qs : batch) { Expectation.check(m_procedureName, qs.stmt.sqlText, i, qs.expectation, results[i]); i++; } // clear the queued sql list for the next call batch.clear(); return results; }
/** * This consumes the header and body from the cursor. The header is consumed first followed by the * body if there is any. There is a body of there is a Content-Length or a Transfer-Encoding * header present. If there is no body then a substitute body is given which has an empty input * stream. * * @param cursor used to consumed the bytes for the entity */ public void consume(Cursor cursor) throws IOException { while (cursor.isReady()) { if (header.isFinished()) { if (body == null) { body = factory.getInstance(); } body.consume(cursor); if (body.isFinished()) { break; } } else { header.consume(cursor); } } if (header.isFinished()) { if (body == null) { expect.execute(header); body = factory.getInstance(); } builder.setBody(body); builder.setHeader(header); } }
@Override public <T> ListenableFuture<T> execute(Request request, AsyncHandler<T> handler) throws IOException { final Expectation expectation = expectations.get(new URL(request.getUrl())); if (expectation == null) { throw new RuntimeException("Unknown URL requested, failing test: " + request.getUrl()); } fulfilledExpectations.add(expectation); T t = null; try { final URI uri = expectation.getUrl().toURI(); handler.onStatusReceived( new HttpResponseStatus(uri, this) { @Override public int getStatusCode() { return expectation.getStatusCode(); } @Override public String getStatusText() { return ""; // TODO } @Override public String getProtocolName() { return expectation.getUrl().getProtocol(); } @Override public int getProtocolMajorVersion() { return 1; } @Override public int getProtocolMinorVersion() { return 1; } @Override public String getProtocolText() { return ""; // TODO } }); handler.onHeadersReceived( new HttpResponseHeaders(uri, this) { @Override public FluentCaseInsensitiveStringsMap getHeaders() { return new FluentCaseInsensitiveStringsMap(); } }); handler.onBodyPartReceived( new HttpResponseBodyPart(uri, this) { @Override public byte[] getBodyPartBytes() { return expectation.getPayload().getBytes(Charset.forName("UTF-8")); } @Override public int writeTo(OutputStream outputStream) throws IOException { final byte[] bodyPartBytes = getBodyPartBytes(); outputStream.write(bodyPartBytes); return bodyPartBytes.length; } @Override public ByteBuffer getBodyByteBuffer() { return ByteBuffer.wrap(getBodyPartBytes()); } @Override public boolean isLast() { return true; } @Override public void markUnderlyingConnectionAsClosed() {} @Override public boolean closeUnderlyingConnection() { return true; } }); t = handler.onCompleted(); } catch (Exception e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } final T finalT = t; final Future<T> futureT = Executors.newSingleThreadExecutor() .submit( new Callable<T>() { @Override public T call() throws Exception { return finalT; } }); return new ImmediateFuture<>(futureT); }