@Test
public void testPopulateResources_multi() throws Exception {

  ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
  Connection connection = createNiceMock(Connection.class);
  Statement statement = createNiceMock(Statement.class);
  ResultSet resultSet = createNiceMock(ResultSet.class);
  // set expectations
  expect(connectionFactory.getConnection()).andReturn(connection).once();
  expect(connection.createStatement()).andReturn(statement).once();
  expect(statement.executeQuery(anyObject(String.class))).andReturn(resultSet).once();
  expect(resultSet.next()).andReturn(true);
  expect(resultSet.getString("RecordTypeContext")).andReturn("rpc");
  expect(resultSet.getString("RecordTypeName")).andReturn("rpc");
  expect(resultSet.getString("TagPairs")).andReturn("");
  expect(resultSet.getString("MetricName")).andReturn("RpcQueueTime_avg_time");
  expect(resultSet.getString("ServiceName")).andReturn("datanode");
  expect(resultSet.getString("NodeName")).andReturn("host1");
  expect(resultSet.getLong("RecordTimeStamp")).andReturn(999990L);
  expect(resultSet.getNString("MetricValue")).andReturn("0");
  expect(resultSet.next()).andReturn(true);
  expect(resultSet.getString("RecordTypeContext")).andReturn("rpc");
  expect(resultSet.getString("RecordTypeName")).andReturn("rpc");
  expect(resultSet.getString("TagPairs")).andReturn("");
  expect(resultSet.getString("MetricName")).andReturn("RpcQueueTime_avg_time");
  expect(resultSet.getString("ServiceName")).andReturn("datanode");
  expect(resultSet.getString("NodeName")).andReturn("host1");
  expect(resultSet.getLong("RecordTimeStamp")).andReturn(999991L);
  expect(resultSet.getNString("MetricValue")).andReturn("1");
  expect(resultSet.next()).andReturn(true);
  expect(resultSet.getString("RecordTypeContext")).andReturn("rpc");
  expect(resultSet.getString("RecordTypeName")).andReturn("rpc");
  expect(resultSet.getString("TagPairs")).andReturn("");
  expect(resultSet.getString("MetricName")).andReturn("RpcSlowResponse_num_ops");
  expect(resultSet.getString("ServiceName")).andReturn("datanode");
  expect(resultSet.getString("NodeName")).andReturn("host1");
  expect(resultSet.getLong("RecordTimeStamp")).andReturn(999992L);
  expect(resultSet.getNString("MetricValue")).andReturn("2");
  expect(resultSet.next()).andReturn(true);
  expect(resultSet.getString("RecordTypeContext")).andReturn("rpc");
  expect(resultSet.getString("RecordTypeName")).andReturn("rpc");
  expect(resultSet.getString("TagPairs")).andReturn("");
  expect(resultSet.getString("MetricName")).andReturn("RpcSlowResponse_num_ops");
  expect(resultSet.getString("ServiceName")).andReturn("datanode");
  expect(resultSet.getString("NodeName")).andReturn("host1");
  expect(resultSet.getLong("RecordTimeStamp")).andReturn(999993L);
  expect(resultSet.getNString("MetricValue")).andReturn("3");
  expect(resultSet.next()).andReturn(false);
  // replay
  replay(connectionFactory, connection, statement, resultSet);
  SQLPropertyProvider provider = new SQLPropertyProvider(
      PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent),
      new TestHostInfoProvider(),
      CLUSTER_NAME_PROPERTY_ID,
      HOST_NAME_PROPERTY_ID,
      COMPONENT_NAME_PROPERTY_ID,
      SERVICE_NAME_PROPERTY_ID,
      connectionFactory);
  // namenode
  Resource resource = new ResourceImpl(Resource.Type.HostComponent);
  resource.setProperty(CLUSTER_NAME_PROPERTY_ID, "c1");
  resource.setProperty(HOST_NAME_PROPERTY_ID, "domU-12-31-39-0E-34-E1.compute-1.internal");
  resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "DATANODE");
  resource.setProperty(SERVICE_NAME_PROPERTY_ID, "HDFS");
  // ask for two properties ... on temporal, one point in time
  Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
  temporalInfoMap.put(PROPERTY_ID_1, new TemporalInfoImpl(10L, 20L, 1L));
  Set<String> propertyIds = new LinkedHashSet<String>();
  propertyIds.add(PROPERTY_ID_1);
  propertyIds.add(PROPERTY_ID_2);
  Request request = PropertyHelper.getReadRequest(propertyIds, temporalInfoMap);
  Assert.assertEquals(1, provider.populateResources(Collections.singleton(resource), request, null).size());
  // check the temporal value
  Assert.assertTrue(resource.getPropertyValue(PROPERTY_ID_1) instanceof Number[][]);
  Number[][] datapoints = (Number[][]) resource.getPropertyValue(PROPERTY_ID_1);
  for (int i = 0; i < datapoints.length; ++i) {
    Assert.assertEquals((long) i, datapoints[i][0]);
    Assert.assertEquals((999990L + i) / 1000, datapoints[i][1]);
  }
  // check the point in time value ... should be the last value of the time series...
  Assert.assertEquals( 3L, resource.getPropertyValue(PROPERTY_ID_2));
  // verify
  verify(connectionFactory, connection, statement, resultSet);
}