use of java.io.Flushable in project j2objc by google.
the class FormatterTest method test_flush.
/**
* java.util.Formatter#flush()
*/
public void test_flush() throws IOException {
Formatter f = null;
f = new Formatter(notExist);
assertTrue(f instanceof Flushable);
f.close();
try {
f.flush();
fail("should throw FormatterClosedException");
} catch (FormatterClosedException e) {
// expected
}
f = new Formatter();
// For destination that does not implement Flushable
// No exception should be thrown
f.flush();
}
use of java.io.Flushable in project neo4j by neo4j.
the class BatchingTransactionAppenderConcurrencyTest method setUp.
@Before
public void setUp() {
class Channel extends InMemoryClosableChannel implements Flushable {
@Override
public Flushable prepareForFlush() {
try {
channelCommandQueue.put(ChannelCommand.emptyBufferIntoChannelAndClearIt);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return this;
}
@Override
public void flush() throws IOException {
try {
forceSemaphore.release();
channelCommandQueue.put(ChannelCommand.force);
} catch (InterruptedException e) {
throw new IOException(e);
}
}
}
when(logFile.getWriter()).thenReturn(new Channel());
}
use of java.io.Flushable in project tomee by apache.
the class FlushableDataSourceHandler method invoke.
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
final CommonDataSource actualDelegate = delegate.get();
if (Object.class == method.getDeclaringClass()) {
if ("hashCode".equals(method.getName())) {
return hashCode();
}
if ("toString".equals(method.getName())) {
return "Flushable[" + actualDelegate.toString() + "]";
}
}
if (Flushable.class == method.getDeclaringClass()) {
final Lock l = lock.writeLock();
l.lock();
try {
createANewDelegate();
if (Flushable.class.isInstance(actualDelegate)) {
// these sanity could be enhanced
if (!Proxy.isProxyClass(actualDelegate.getClass()) || // reset implies flush so we need to check both
(!FlushableDataSourceHandler.class.isInstance(Proxy.getInvocationHandler(actualDelegate)) && !ResettableDataSourceHandler.class.isInstance(Proxy.getInvocationHandler(actualDelegate)))) {
Flushable.class.cast(actualDelegate).flush();
}
}
} finally {
l.unlock();
}
return null;
}
final Lock l = lock.readLock();
l.lock();
try {
return method.invoke(getDelegate(), args);
} catch (final InvocationTargetException ite) {
throw ite.getCause();
} finally {
l.unlock();
}
}
use of java.io.Flushable in project closure-templates by google.
the class RenderVisitorTest method testRenderFuture.
@Test
public void testRenderFuture() throws Exception {
final StringBuilder progress = new StringBuilder();
Flushable flushable = new Flushable() {
@Override
public void flush() {
progress.append("flush;");
}
};
String soyFileContent = "{namespace ns}\n" + "\n" + "/** @param boo @param foo @param goo */\n" + "{template .callerTemplate autoescape=\"deprecated-noncontextual\"}\n" + " {call .calleeTemplate data=\"all\" /}\n" + " {call .calleeTemplate data=\"$foo\" /}\n" + " {call .calleeTemplate data=\"all\"}\n" + " {param boo: $foo.boo /}\n" + " {/call}\n" + " {call .calleeTemplate data=\"all\"}\n" + " {param boo: 'moo' /}\n" + " {/call}\n" + " {call .calleeTemplate data=\"$foo\"}\n" + " {param boo}moo{/param}\n" + " {/call}\n" + " {call .calleeTemplate}\n" + " {param boo}zoo{/param}\n" + " {param goo: $foo.goo /}\n" + " {/call}\n" + "{/template}\n" + "\n" + "/**\n" + " * @param boo\n" + " * @param goo\n" + " */\n" + "{template .calleeTemplate autoescape=\"deprecated-noncontextual\"}\n" + " {$boo}{$ij.future}\n" + " {for $n in $goo} {$n}{/for}{\\n}\n" + "{/template}\n";
TemplateRegistry templateRegistry = SoyFileSetParserBuilder.forFileContents(soyFileContent).errorReporter(FAIL).parse().registry();
SoyDict foo = SoyValueConverterUtility.newDict("boo", new TestFuture("foo", progress), "goo", SoyValueConverterUtility.newList(3, 2, 1));
SoyDict data = SoyValueConverterUtility.newDict("boo", new TestFuture("boo", progress), "foo", foo, "goo", SoyValueConverterUtility.newList(1, 2, 3));
SoyRecord testIj = SoyValueConverterUtility.newDict("future", new TestFuture("ij", progress));
StringBuilder outputSb = new StringBuilder();
CountingFlushableAppendable output = new CountingFlushableAppendable(outputSb, flushable);
RenderVisitor rv = new RenderVisitor(new EvalVisitorFactoryImpl(), output, templateRegistry, data, testIj, Predicates.<String>alwaysFalse(), null, xidRenamingMap, cssRenamingMap, false);
rv.exec(templateRegistry.getBasicTemplate("ns.callerTemplate"));
String expectedOutput = "booij 1 2 3\n" + "fooij 3 2 1\n" + "fooij 1 2 3\n" + "mooij 1 2 3\n" + "mooij 3 2 1\n" + "zooij 3 2 1\n";
assertThat(outputSb.toString()).isEqualTo(expectedOutput);
assertThat(progress.toString()).isEqualTo("booflush;ijflush;foo");
}
use of java.io.Flushable in project neo4j by neo4j.
the class PageCacheTest method flushAndForceMustTolerateAsynchronousFileUnmapping.
@Test
void flushAndForceMustTolerateAsynchronousFileUnmapping() throws Exception {
configureStandardPageCache();
Path a = existingFile("a");
Path b = existingFile("b");
Path c = existingFile("c");
BinaryLatch limiterStartLatch = new BinaryLatch();
BinaryLatch limiterBlockLatch = new BinaryLatch();
var ioController = new EmptyIOController() {
@Override
public void maybeLimitIO(int recentlyCompletedIOs, Flushable flushable, MajorFlushEvent flushEvent) {
limiterStartLatch.release();
limiterBlockLatch.await();
super.maybeLimitIO(recentlyCompletedIOs, flushable, flushEvent);
}
};
Future<?> flusher;
try (PagedFile pfA = pageCache.map(a, filePageSize, DEFAULT_DATABASE_NAME, immutable.empty(), ioController);
PagedFile pfB = pageCache.map(b, filePageSize, DEFAULT_DATABASE_NAME, immutable.empty(), ioController);
PagedFile pfC = pageCache.map(c, filePageSize, DEFAULT_DATABASE_NAME, immutable.empty(), ioController)) {
// Dirty a bunch of pages.
try (PageCursor cursor = pfA.io(0, PF_SHARED_WRITE_LOCK, NULL)) {
assertTrue(cursor.next());
}
try (PageCursor cursor = pfB.io(0, PF_SHARED_WRITE_LOCK, NULL)) {
assertTrue(cursor.next());
}
try (PageCursor cursor = pfC.io(0, PF_SHARED_WRITE_LOCK, NULL)) {
assertTrue(cursor.next());
}
flusher = executor.submit(() -> {
pfA.flushAndForce();
pfB.flushAndForce();
pfC.flushAndForce();
return null;
});
// Flusher is now stuck inside flushAndForce.
limiterStartLatch.await();
}
// We should be able to unmap all the files.
// And then when the flusher resumes again, it should not throw any exceptions from the asynchronously
// closed files.
limiterBlockLatch.release();
// This must not throw.
flusher.get();
}
Aggregations