use of java.io.Closeable in project neo4j by neo4j.
the class QueryLoggerKernelExtension method newInstance.
@Override
public Lifecycle newInstance(@SuppressWarnings("unused") KernelContext context, final Dependencies dependencies) throws Throwable {
final Config config = dependencies.config();
boolean queryLogEnabled = config.get(GraphDatabaseSettings.log_queries);
final File queryLogFile = config.get(GraphDatabaseSettings.log_queries_filename);
final FileSystemAbstraction fileSystem = dependencies.fileSystem();
final JobScheduler jobScheduler = dependencies.jobScheduler();
final Monitors monitoring = dependencies.monitoring();
if (!queryLogEnabled) {
return createEmptyAdapter();
}
return new LifecycleAdapter() {
Closeable closable;
@Override
public void init() throws Throwable {
Long thresholdMillis = config.get(GraphDatabaseSettings.log_queries_threshold);
Long rotationThreshold = config.get(GraphDatabaseSettings.log_queries_rotation_threshold);
int maxArchives = config.get(GraphDatabaseSettings.log_queries_max_archives);
boolean logQueryParameters = config.get(GraphDatabaseSettings.log_queries_parameter_logging_enabled);
FormattedLog.Builder logBuilder = FormattedLog.withUTCTimeZone();
Log log;
if (rotationThreshold == 0) {
OutputStream logOutputStream = createOrOpenAsOuputStream(fileSystem, queryLogFile, true);
log = logBuilder.toOutputStream(logOutputStream);
closable = logOutputStream;
} else {
RotatingFileOutputStreamSupplier rotatingSupplier = new RotatingFileOutputStreamSupplier(fileSystem, queryLogFile, rotationThreshold, 0, maxArchives, jobScheduler.executor(JobScheduler.Groups.queryLogRotation));
log = logBuilder.toOutputStream(rotatingSupplier);
closable = rotatingSupplier;
}
QueryLogger logger = new QueryLogger(Clocks.systemClock(), log, thresholdMillis, logQueryParameters);
monitoring.addMonitorListener(logger);
}
@Override
public void shutdown() throws Throwable {
closable.close();
}
};
}
use of java.io.Closeable in project presto by prestodb.
the class Verifier method run.
// Returns number of failed queries
public int run(List<QueryPair> queries) throws InterruptedException {
ExecutorService executor = newFixedThreadPool(threadCount);
CompletionService<Validator> completionService = new ExecutorCompletionService<>(executor);
int totalQueries = queries.size() * config.getSuiteRepetitions();
log.info("Total Queries: %d", totalQueries);
log.info("Whitelisted Queries: %s", Joiner.on(',').join(whitelist));
int queriesSubmitted = 0;
for (int i = 0; i < config.getSuiteRepetitions(); i++) {
for (QueryPair query : queries) {
for (int j = 0; j < config.getQueryRepetitions(); j++) {
// If a whitelist exists, only run the tests on the whitelist
if (!whitelist.isEmpty() && !whitelist.contains(query.getName())) {
log.debug("Query %s is not whitelisted", query.getName());
continue;
}
if (blacklist.contains(query.getName())) {
log.debug("Query %s is blacklisted", query.getName());
continue;
}
Validator validator = new Validator(config.getControlGateway(), config.getTestGateway(), config.getControlTimeout(), config.getTestTimeout(), config.getMaxRowCount(), config.isExplainOnly(), config.getDoublePrecision(), isCheckCorrectness(query), true, config.isVerboseResultsComparison(), config.getControlTeardownRetries(), config.getTestTeardownRetries(), query);
completionService.submit(validator::valid, validator);
queriesSubmitted++;
}
}
}
log.info("Allowed Queries: %d", queriesSubmitted);
log.info("Skipped Queries: %d", (totalQueries - queriesSubmitted));
log.info("---------------------");
executor.shutdown();
int total = 0;
int valid = 0;
int failed = 0;
int skipped = 0;
double lastProgress = 0;
while (total < queriesSubmitted) {
total++;
Validator validator = takeUnchecked(completionService);
if (validator.isSkipped()) {
if (!config.isQuiet()) {
log.warn("%s", validator.getSkippedMessage());
}
skipped++;
continue;
}
if (validator.valid()) {
valid++;
} else {
failed++;
}
for (EventClient eventClient : eventClients) {
eventClient.post(buildEvent(validator));
}
double progress = (((double) total) / totalQueries) * 100;
if (!config.isQuiet() || (progress - lastProgress) > 1) {
log.info("Progress: %s valid, %s failed, %s skipped, %.2f%% done", valid, failed, skipped, progress);
lastProgress = progress;
}
}
log.info("Results: %s / %s (%s skipped)", valid, failed, skipped);
log.info("");
for (EventClient eventClient : eventClients) {
if (eventClient instanceof Closeable) {
try {
((Closeable) eventClient).close();
} catch (IOException ignored) {
}
log.info("");
}
}
return failed;
}
use of java.io.Closeable in project requery by requery.
the class SqlCipherMetaData method queryMemory.
@Override
protected <R> R queryMemory(Function<Cursor, R> function, String query) throws SQLException {
try {
final SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(":memory:", "", null);
Cursor cursor = database.rawQuery(query, null);
return function.apply(closeWithCursor(new Closeable() {
@Override
public void close() throws IOException {
database.close();
}
}, cursor));
} catch (SQLiteException e) {
throw new SQLException(e);
}
}
use of java.io.Closeable in project byte-buddy by raphw.
the class ClassFileLocatorForJarFileTest method testJarFileClosable.
@Test
public void testJarFileClosable() throws Exception {
JarFile jarFile = mock(JarFile.class);
Closeable classFileLocator = new ClassFileLocator.ForJarFile(jarFile);
classFileLocator.close();
verify(jarFile).close();
}
use of java.io.Closeable in project spring-boot by spring-projects.
the class SampleBitronixApplication method main.
public static void main(String[] args) throws Exception {
ApplicationContext context = SpringApplication.run(SampleBitronixApplication.class, args);
AccountService service = context.getBean(AccountService.class);
AccountRepository repository = context.getBean(AccountRepository.class);
service.createAccountAndNotify("josh");
System.out.println("Count is " + repository.count());
try {
service.createAccountAndNotify("error");
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
System.out.println("Count is " + repository.count());
Thread.sleep(100);
((Closeable) context).close();
}
Aggregations