Mercurial > hg > release > thermostat-1.4
changeset 1501:914a5b12e044
Fix mistake in storage-profile's single query
Reviewed-by: jerboaa
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2014-August/010540.html
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Thu, 21 Aug 2014 09:46:45 -0400 |
parents | ff2313f0505a |
children | c50bc474711d |
files | storage-profile/common/src/main/java/com/redhat/thermostat/storage/profile/internal/StorageProfileCommand.java |
diffstat | 1 files changed, 46 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/storage-profile/common/src/main/java/com/redhat/thermostat/storage/profile/internal/StorageProfileCommand.java Thu Aug 21 12:17:51 2014 +0200 +++ b/storage-profile/common/src/main/java/com/redhat/thermostat/storage/profile/internal/StorageProfileCommand.java Thu Aug 21 09:46:45 2014 -0400 @@ -129,6 +129,10 @@ clearAndVerifyAllData(console); + measureQueryNoResult(console, iterations); + + clearAndVerifyAllData(console); + measureQuerySingleItem(console, iterations); clearAndVerifyAllData(console); @@ -199,7 +203,7 @@ } } - private void measureQuerySingleItem(Console console, final int ITERATIONS) { + private void measureQueryNoResult(Console console, final int ITERATIONS) { try { StatementDescriptor<SimpleData> desc = new StatementDescriptor<>(PROFILE_CATEGORY, QUERY_ALL_DATA); long start = System.nanoTime(); @@ -211,8 +215,47 @@ } } long end = System.nanoTime(); - console.getOutput().println("QUERY (x" + ITERATIONS + ") took " + nanosToMicroSeconds(end-start)); - console.getOutput().println("QUERY avg was " + nanosToMicroSeconds(1.0 * (end-start) / ITERATIONS)); + console.getOutput().println("QUERY no-result (x" + ITERATIONS + ") took " + nanosToMicroSeconds(end-start)); + console.getOutput().println("QUERY no-result avg was " + nanosToMicroSeconds(1.0 * (end-start) / ITERATIONS)); + } catch (StatementExecutionException e) { + console.getError().println("Error QUERYing data"); + e.printStackTrace(console.getError()); + } catch (DescriptorParsingException parsingException) { + throw new AssertionError("The descriptor must be valid", parsingException); + } + } + + private void measureQuerySingleItem(Console console, final int ITERATIONS) { + try { + + // populate single data item + StatementDescriptor<SimpleData> addDesc = new StatementDescriptor<>(PROFILE_CATEGORY, INSERT_DATA); + PreparedStatement<SimpleData> insertStatement = storage.prepareStatement(addDesc); + insertStatement.setString(0, "FOO"); + insertStatement.setString(1, "BAR"); + insertStatement.setLong(2, 1); + insertStatement.execute(); + + waitForDataCount(console, 1); + + // time query + StatementDescriptor<SimpleData> desc = new StatementDescriptor<>(PROFILE_CATEGORY, QUERY_ALL_DATA); + long start = System.nanoTime(); + for (int i = 0; i < ITERATIONS; i++) { + PreparedStatement<SimpleData> statement = storage.prepareStatement(desc); + Cursor<SimpleData> results = statement.executeQuery(); + boolean firstResult = true; + while (results.hasNext()) { + /* discard = */ results.next(); + if (!firstResult) { + throw new AssertionError("Unexpected reuslts"); + } + firstResult = false; + } + } + long end = System.nanoTime(); + console.getOutput().println("QUERY single (x" + ITERATIONS + ") took " + nanosToMicroSeconds(end-start)); + console.getOutput().println("QUERY single avg was " + nanosToMicroSeconds(1.0 * (end-start) / ITERATIONS )); } catch (StatementExecutionException e) { console.getError().println("Error QUERYing data"); e.printStackTrace(console.getError());