@Test public void testAsynchronePublication() throws InterruptedException { assertEquals(0, MockWriter.getNbLog()); IStoreWriter tWriter = (IStoreWriter) applicationContext.getBean(IStoreWriter.STORE_WRITER_NAME); // Log NB_FLOW_TO_LOG ExecutionFlowPO[] tFlows = new ExecutionFlowPO[NB_FLOW_TO_LOG]; for (int i = 0; i < NB_FLOW_TO_LOG; i++) { tFlows[i] = buildNewFullFlow(); } for (int i = 0; i < NB_FLOW_TO_LOG; i++) { tWriter.writeExecutionFlow(tFlows[i]); } assertTrue( "All flow should not be writtren synchronously", NB_FLOW_TO_LOG > MockWriter.getNbLog()); int i = 0; while (i < NB_TIME_TO_WAIT && NB_FLOW_TO_LOG != MockWriter.getNbLog()) { Thread.sleep(TIME_TO_WAIT); i++; } assertEquals(NB_FLOW_TO_LOG, MockWriter.getNbLog()); }
/** @tests java.io.BufferedWriter#close() */ public void test_close() throws IOException { try { bw.close(); bw.write(testString); fail("Writing to a closed stream should throw IOException"); } catch (IOException e) { // Expected } assertTrue("Write after close", !sw.toString().equals(testString)); // Regression test for HARMONY-4178 MockWriter mw = new MockWriter(); BufferedWriter bw = new BufferedWriter(mw); bw.write('a'); bw.close(); // flush should not be called on underlying stream assertFalse("Flush was called in the underlying stream", mw.isFlushCalled()); // on the other hand the BufferedWriter itself should flush the // buffer assertEquals("BufferdWriter do not flush itself before close", "a", mw.getWritten()); }
@Before public void init() throws Exception { MockWriter.clear(); }