Java Code Examples for com.mockrunner.mock.jdbc.MockResultSet#next()

The following examples show how to use com.mockrunner.mock.jdbc.MockResultSet#next() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetricDataRowCallbackHandlerTest.java    From graphouse with Apache License 2.0 6 votes vote down vote up
@Test
public void testEmpty() throws Exception {
    MockResultSet resultSet = new MockResultSet("data");

    StringWriter stringWriter = new StringWriter();
    JsonWriter jsonWriter = new JsonWriter(stringWriter);
    jsonWriter.beginObject();

    MetricDataRowCallbackHandler handler = new MetricDataRowCallbackHandler(
        jsonWriter, new MetricDataQueryParams(0, 3, 1), Collections.emptySet()
    );

    while (resultSet.next()) {
        handler.processRow(resultSet);
    }
    handler.finish();
    jsonWriter.endObject();

    Assert.assertEquals("{}", stringWriter.toString());

}
 
Example 2
Source File: MetricDataRowCallbackHandlerTest.java    From graphouse with Apache License 2.0 5 votes vote down vote up
@Test
public void testHandler() throws Exception {

    MockResultSet resultSet = new MockResultSet("data");
    resultSet.addColumn("metric", new String[]{"name1", "name1", "name2", "name2"});
    resultSet.addColumn("ts", new Integer[]{100, 160, 160, 220});
    resultSet.addColumn("value", new Double[]{33.33, 42.0, 32.0, 77.7});

    StringWriter stringWriter = new StringWriter();
    JsonWriter jsonWriter = new JsonWriter(stringWriter);
    jsonWriter.beginObject();

    MetricDataRowCallbackHandler handler = new MetricDataRowCallbackHandler(
        jsonWriter, new MetricDataQueryParams(100, 280, 60), Collections.emptySet()
    );

    while (resultSet.next()) {
        handler.processRow(resultSet);
    }
    handler.finish();

    jsonWriter.endObject();

    JsonObject expected = new JsonObject();
    expected.add("name1", createMetric(100, 280, 60, 33.33, 42.0, Double.NaN));
    expected.add("name2", createMetric(100, 280, 60, Double.NaN, 32.0, 77.7));


    Assert.assertEquals(expected.toString(), stringWriter.toString());
}
 
Example 3
Source File: MetricDataRowCallbackHandlerTest.java    From graphouse with Apache License 2.0 5 votes vote down vote up
@Test
public void testChNan() throws Exception {

    MockResultSet resultSet = new MockResultSet("data");
    resultSet.addColumn("metric", new String[]{"name1", "name1", "name1"});
    resultSet.addColumn("ts", new Integer[]{0, 1, 2});
    resultSet.addColumn("value", new Double[]{0.0, Double.NaN, 2.0});

    StringWriter stringWriter = new StringWriter();
    JsonWriter jsonWriter = new JsonWriter(stringWriter);
    jsonWriter.beginObject();

    MetricDataRowCallbackHandler handler = new MetricDataRowCallbackHandler(
        jsonWriter, new MetricDataQueryParams(0, 3, 1), Collections.emptySet()
    );

    while (resultSet.next()) {
        handler.processRow(resultSet);
    }
    handler.finish();

    jsonWriter.endObject();

    JsonObject expected = new JsonObject();
    expected.add("name1", createMetric(0, 3, 1, 0.0, Double.NaN, 2.0));

    Assert.assertEquals(expected.toString(), stringWriter.toString());
}
 
Example 4
Source File: MetricDataRowCallbackHandlerTest.java    From graphouse with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyMetricFilling() throws Exception {
    MockResultSet resultSet = new MockResultSet("data");
    resultSet.addColumn("metric", new String[]{"name1", "name1"});
    resultSet.addColumn("ts", new Integer[]{100, 160});
    resultSet.addColumn("value", new Double[]{33.33, 42.0});

    StringWriter stringWriter = new StringWriter();
    JsonWriter jsonWriter = new JsonWriter(stringWriter);
    jsonWriter.beginObject();

    MetricDataRowCallbackHandler handler = new MetricDataRowCallbackHandler(
        jsonWriter, new MetricDataQueryParams(100, 280, 60), new LinkedHashSet<>(Arrays.asList("name1", "name2", "name3"))
    );

    while (resultSet.next()) {
        handler.processRow(resultSet);
    }
    handler.finish();

    jsonWriter.endObject();

    JsonObject expected = new JsonObject();
    expected.add("name1", createMetric(100, 280, 60, 33.33, 42.0, Double.NaN));
    expected.add("name2", createMetric(100, 280, 60, Double.NaN, Double.NaN, Double.NaN));
    expected.add("name3", createMetric(100, 280, 60, Double.NaN, Double.NaN, Double.NaN));

    Assert.assertEquals(expected.toString(), stringWriter.toString());
}
 
Example 5
Source File: JdbcBenchmark.java    From spring-data-dev-tools with Apache License 2.0 5 votes vote down vote up
@Benchmark
public void convertWithSpringData(Blackhole sink) throws Exception {

	MockResultSet resultSet = new MockResultSet("book");
	resultSet.addColumns(columns);
	resultSet.addRow(values);
	resultSet.next();

	sink.consume(this.bookEntityMapper.mapRow(resultSet, 1));
}