示例#1
0
  @Test
  public void testRemovingUselessData() throws SQLException, InterruptedException {
    SystemTime wrapper = new SystemTime();
    sm.executeCreateTable(wrapper.getDBAliasInStr(), new DataField[] {}, true);
    wrapper.setActiveAddressBean(
        new AddressBean("system-time", new KeyValueImp(SystemTime.CLOCK_PERIOD_KEY, "100")));
    assertTrue(wrapper.initialize());
    Thread thread = new Thread(wrapper);
    InputStream is = new InputStream();
    StreamSource ss =
        new StreamSource()
            .setAlias("my-stream")
            .setAddressing(new AddressBean[] {new AddressBean("system-time")})
            .setSqlQuery("select * from wrapper where TIMED <0")
            .setRawHistorySize("2")
            .setInputStream(is);
    ss.setSamplingRate(1);
    ss.setWrapper(wrapper);
    assertTrue(ss.validate());
    assertEquals(wrapper.getTimerClockPeriod(), 100);
    thread.start();
    Thread.sleep(1000);

    ResultSet rs =
        sm.executeQueryWithResultSet(
            new StringBuilder("select count(*) from ").append(wrapper.getDBAliasInStr()),
            sm.getConnection());
    assertTrue(rs.next());
    //    System.out.println(rs.getInt(1));
    assertTrue(
        rs.getInt(1) <= (AbstractWrapper.GARBAGE_COLLECT_AFTER_SPECIFIED_NO_OF_ELEMENTS * 2));
    wrapper.releaseResources();
  }
示例#2
0
 /**
  * Test method for {@link
  * org.openiot.gsn.wrappers.AbstractWrapper#sendToWrapper(java.lang.Object)}. Test to see what is
  * the behavior if the wrapper is disabled.
  *
  * @throws OperationNotSupportedException
  * @throws SQLException
  */
 @Test(expected = GSNRuntimeException.class)
 public void testSendToWrapper2() throws OperationNotSupportedException, SQLException {
   SystemTime systemTimeWrapper = new SystemTime();
   systemTimeWrapper.setActiveAddressBean(new AddressBean("system-time"));
   assertTrue(systemTimeWrapper.initialize());
   Thread thread = new Thread(systemTimeWrapper);
   thread.start();
   systemTimeWrapper.releaseResources();
   systemTimeWrapper.sendToWrapper("bla");
 }