@Test public void shouldRunReadOnlyLdbcWorkloadWithNothingDbAndCrashInSaneManner() throws InterruptedException, DbException, WorkloadException, IOException, MetricsCollectionException, CompletionTimeException, DriverConfigurationException, ExecutionException { int threadCount = 4; long operationCount = 100000; ControlService controlService = null; Db db = null; Workload workload = null; MetricsService metricsService = null; CompletionTimeService completionTimeService = null; ConcurrentErrorReporter errorReporter = new ConcurrentErrorReporter(); try { Map<String, String> paramsMap = LdbcSnbInteractiveWorkloadConfiguration.defaultReadOnlyConfigSF1(); paramsMap.put( LdbcSnbInteractiveWorkloadConfiguration.PARAMETERS_DIRECTORY, TestUtils.getResource("/snb/interactive/").getAbsolutePath()); paramsMap.put( LdbcSnbInteractiveWorkloadConfiguration.UPDATES_DIRECTORY, TestUtils.getResource("/snb/interactive/").getAbsolutePath()); // Driver-specific parameters String name = null; String dbClassName = DummyLdbcSnbInteractiveDb.class.getName(); String workloadClassName = LdbcSnbInteractiveWorkload.class.getName(); int statusDisplayInterval = 1; TimeUnit timeUnit = TimeUnit.NANOSECONDS; String resultDirPath = temporaryFolder.newFolder().getAbsolutePath(); double timeCompressionRatio = 0.0000001; Set<String> peerIds = new HashSet<>(); ConsoleAndFileDriverConfiguration.ConsoleAndFileValidationParamOptions validationParams = null; String dbValidationFilePath = null; boolean calculateWorkloadStatistics = false; long spinnerSleepDuration = 0l; boolean printHelp = false; boolean ignoreScheduledStartTimes = false; long warmupCount = 100; ConsoleAndFileDriverConfiguration configuration = new ConsoleAndFileDriverConfiguration( paramsMap, name, dbClassName, workloadClassName, operationCount, threadCount, statusDisplayInterval, timeUnit, resultDirPath, timeCompressionRatio, peerIds, validationParams, dbValidationFilePath, calculateWorkloadStatistics, spinnerSleepDuration, printHelp, ignoreScheduledStartTimes, warmupCount); configuration = (ConsoleAndFileDriverConfiguration) configuration.applyArgs( MapUtils.loadPropertiesToMap( TestUtils.getResource("/snb/interactive/updateStream.properties"))); controlService = new LocalControlService( timeSource.nowAsMilli(), configuration, new Log4jLoggingServiceFactory(false), timeSource); LoggingService loggingService = new Log4jLoggingServiceFactory(false).loggingServiceFor("Test"); GeneratorFactory gf = new GeneratorFactory(new RandomDataGeneratorFactory(42L)); boolean returnStreamsWithDbConnector = true; Tuple3<WorkloadStreams, Workload, Long> workloadStreamsAndWorkload = WorkloadStreams.createNewWorkloadWithOffsetAndLimitedWorkloadStreams( configuration, gf, returnStreamsWithDbConnector, configuration.warmupCount(), configuration.operationCount(), LOGGING_SERVICE_FACTORY); workload = workloadStreamsAndWorkload._2(); WorkloadStreams workloadStreams = WorkloadStreams.timeOffsetAndCompressWorkloadStreams( workloadStreamsAndWorkload._1(), controlService.workloadStartTimeAsMilli(), configuration.timeCompressionRatio(), gf); File resultsLog = temporaryFolder.newFile(); SimpleCsvFileWriter csvResultsLogWriter = new SimpleCsvFileWriter(resultsLog, SimpleCsvFileWriter.DEFAULT_COLUMN_SEPARATOR); metricsService = ThreadedQueuedMetricsService.newInstanceUsingBlockingBoundedQueue( timeSource, errorReporter, configuration.timeUnit(), ThreadedQueuedMetricsService.DEFAULT_HIGHEST_EXPECTED_RUNTIME_DURATION_AS_NANO, csvResultsLogWriter, workload.operationTypeToClassMapping(), LOGGING_SERVICE_FACTORY); completionTimeService = completionTimeServiceAssistant.newSynchronizedConcurrentCompletionTimeServiceFromPeerIds( controlService.configuration().peerIds()); db = new DummyLdbcSnbInteractiveDb(); db.init( configuration .applyArg(DummyLdbcSnbInteractiveDb.CRASH_ON_ARG, LdbcQuery4.class.getName()) .asMap(), loggingService, workload.operationTypeToClassMapping()); int boundedQueueSize = DefaultQueues.DEFAULT_BOUND_1000; WorkloadRunner runner = new WorkloadRunner( timeSource, db, workloadStreams, metricsService, errorReporter, completionTimeService, controlService.loggingServiceFactory(), controlService.configuration().threadCount(), controlService.configuration().statusDisplayIntervalAsSeconds(), controlService.configuration().spinnerSleepDurationAsMilli(), controlService.configuration().ignoreScheduledStartTimes(), boundedQueueSize); runner.getFuture().get(); csvResultsLogWriter.close(); } finally { try { controlService.shutdown(); } catch (Throwable e) { System.out.println( format( "Unclean %s shutdown -- but it's OK", controlService.getClass().getSimpleName())); } try { db.close(); } catch (Throwable e) { System.out.println( format("Unclean %s shutdown -- but it's OK", db.getClass().getSimpleName())); } try { workload.close(); } catch (Throwable e) { System.out.println( format("Unclean %s shutdown -- but it's OK", workload.getClass().getSimpleName())); } try { metricsService.shutdown(); } catch (Throwable e) { System.out.println( format( "Unclean %s shutdown -- but it's OK", metricsService.getClass().getSimpleName())); } try { completionTimeService.shutdown(); } catch (Throwable e) { System.out.println( format( "Unclean %s shutdown -- but it's OK", completionTimeService.getClass().getSimpleName())); } System.out.println(errorReporter.toString()); assertTrue(errorReporter.errorEncountered()); } }
public void doShouldRunReadOnlyLdbcWorkloadWithNothingDbWhileIgnoringScheduledStartTimesAndReturnExpectedMetrics( int threadCount, long operationCount, CompletionTimeService completionTimeService, ConcurrentErrorReporter errorReporter) throws InterruptedException, DbException, WorkloadException, IOException, MetricsCollectionException, CompletionTimeException, DriverConfigurationException, ExecutionException { ControlService controlService = null; Db db = null; Workload workload = null; MetricsService metricsService = null; try { Map<String, String> paramsMap = LdbcSnbInteractiveWorkloadConfiguration.defaultReadOnlyConfigSF1(); paramsMap.put( LdbcSnbInteractiveWorkloadConfiguration.PARAMETERS_DIRECTORY, TestUtils.getResource("/snb/interactive/").getAbsolutePath()); paramsMap.put( LdbcSnbInteractiveWorkloadConfiguration.UPDATES_DIRECTORY, TestUtils.getResource("/snb/interactive/").getAbsolutePath()); // Driver-specific parameters String name = null; String dbClassName = DummyLdbcSnbInteractiveDb.class.getName(); String workloadClassName = LdbcSnbInteractiveWorkload.class.getName(); int statusDisplayInterval = 1; TimeUnit timeUnit = TimeUnit.NANOSECONDS; String resultDirPath = temporaryFolder.newFolder().getAbsolutePath(); double timeCompressionRatio = 1.0; Set<String> peerIds = new HashSet<>(); ConsoleAndFileDriverConfiguration.ConsoleAndFileValidationParamOptions validationParams = null; String dbValidationFilePath = null; boolean calculateWorkloadStatistics = false; long spinnerSleepDuration = 0l; boolean printHelp = false; boolean ignoreScheduledStartTimes = true; long warmupCount = 100; ConsoleAndFileDriverConfiguration configuration = new ConsoleAndFileDriverConfiguration( paramsMap, name, dbClassName, workloadClassName, operationCount, threadCount, statusDisplayInterval, timeUnit, resultDirPath, timeCompressionRatio, peerIds, validationParams, dbValidationFilePath, calculateWorkloadStatistics, spinnerSleepDuration, printHelp, ignoreScheduledStartTimes, warmupCount); configuration = (ConsoleAndFileDriverConfiguration) configuration.applyArgs( MapUtils.loadPropertiesToMap( TestUtils.getResource("/snb/interactive/updateStream.properties"))); controlService = new LocalControlService( timeSource.nowAsMilli() + 1000, configuration, new Log4jLoggingServiceFactory(false), timeSource); LoggingService loggingService = new Log4jLoggingServiceFactory(false).loggingServiceFor("Test"); workload = new LdbcSnbInteractiveWorkload(); workload.init(configuration); db = new DummyLdbcSnbInteractiveDb(); db.init(configuration.asMap(), loggingService, workload.operationTypeToClassMapping()); GeneratorFactory gf = new GeneratorFactory(new RandomDataGeneratorFactory(42L)); Iterator<Operation> operations = gf.limit( WorkloadStreams.mergeSortedByStartTimeExcludingChildOperationGenerators( gf, workload.streams(gf, true)), configuration.operationCount()); Iterator<Operation> timeMappedOperations = gf.timeOffsetAndCompress(operations, controlService.workloadStartTimeAsMilli(), 1.0); WorkloadStreams workloadStreams = new WorkloadStreams(); workloadStreams.setAsynchronousStream( new HashSet<Class<? extends Operation>>(), new HashSet<Class<? extends Operation>>(), Collections.<Operation>emptyIterator(), timeMappedOperations, null); File resultsLog = temporaryFolder.newFile(); SimpleCsvFileWriter csvResultsLogWriter = new SimpleCsvFileWriter(resultsLog, SimpleCsvFileWriter.DEFAULT_COLUMN_SEPARATOR); metricsService = ThreadedQueuedMetricsService.newInstanceUsingBlockingBoundedQueue( timeSource, errorReporter, configuration.timeUnit(), ThreadedQueuedMetricsService.DEFAULT_HIGHEST_EXPECTED_RUNTIME_DURATION_AS_NANO, csvResultsLogWriter, workload.operationTypeToClassMapping(), LOGGING_SERVICE_FACTORY); int boundedQueueSize = DefaultQueues.DEFAULT_BOUND_1000; WorkloadRunner runner = new WorkloadRunner( timeSource, db, workloadStreams, metricsService, errorReporter, completionTimeService, controlService.loggingServiceFactory(), controlService.configuration().threadCount(), controlService.configuration().statusDisplayIntervalAsSeconds(), controlService.configuration().spinnerSleepDurationAsMilli(), controlService.configuration().ignoreScheduledStartTimes(), boundedQueueSize); runner.getFuture().get(); WorkloadResultsSnapshot workloadResults = metricsService.getWriter().results(); SimpleDetailedWorkloadMetricsFormatter metricsFormatter = new SimpleDetailedWorkloadMetricsFormatter(); assertThat( errorReporter.toString() + "\n" + metricsFormatter.format(workloadResults), errorReporter.errorEncountered(), is(false)); assertThat( errorReporter.toString() + "\n" + metricsFormatter.format(workloadResults), workloadResults.latestFinishTimeAsMilli() >= workloadResults.startTimeAsMilli(), is(true)); assertThat( errorReporter.toString() + "\n" + metricsFormatter.format(workloadResults), workloadResults.totalOperationCount(), is(operationCount)); WorkloadResultsSnapshot workloadResultsFromJson = WorkloadResultsSnapshot.fromJson(workloadResults.toJson()); assertThat(errorReporter.toString(), workloadResults, equalTo(workloadResultsFromJson)); assertThat( errorReporter.toString(), workloadResults.toJson(), equalTo(workloadResultsFromJson.toJson())); csvResultsLogWriter.close(); SimpleCsvFileReader csvResultsLogReader = new SimpleCsvFileReader( resultsLog, SimpleCsvFileReader.DEFAULT_COLUMN_SEPARATOR_REGEX_STRING); assertThat( (long) Iterators.size(csvResultsLogReader), is(configuration.operationCount())); // NOT + 1 because I didn't add csv headers csvResultsLogReader.close(); operationCount = metricsService.getWriter().results().totalOperationCount(); double operationsPerSecond = Math.round( ((double) operationCount / workloadResults.totalRunDurationAsNano()) * ONE_SECOND_AS_NANO); double microSecondPerOperation = (double) TimeUnit.NANOSECONDS.toMicros(workloadResults.totalRunDurationAsNano()) / operationCount; System.out.println( format( "[%s threads] Completed %s operations in %s = %s op/sec = 1 op/%s us", threadCount, numberFormatter.format(operationCount), TEMPORAL_UTIL.nanoDurationToString(workloadResults.totalRunDurationAsNano()), doubleNumberFormatter.format(operationsPerSecond), doubleNumberFormatter.format(microSecondPerOperation))); } finally { System.out.println(errorReporter.toString()); if (null != controlService) { controlService.shutdown(); } if (null != db) { db.close(); } if (null != workload) { workload.close(); } if (null != metricsService) { metricsService.shutdown(); } if (null != completionTimeService) { completionTimeService.shutdown(); } } }