コード例 #1
0
 @Test
 public void testStopLoading() throws IOException {
   VSensorConfig sensorConfig = new VSensorConfig();
   sensorConfig.setName("test");
   File someFile = File.createTempFile("bla", ".xml");
   sensorConfig.setMainClass("org.openiot.gsn.vsensor.BridgeVirtualSensor");
   sensorConfig.setFileName(someFile.getAbsolutePath());
   VirtualSensor pool = new VirtualSensor(sensorConfig);
   InputStream is = new InputStream();
   is.setInputStreamName("t1");
   is.setQuery("select * from my-stream1");
   StreamSource ss1 =
       new StreamSource()
           .setAlias("my-stream1")
           .setAddressing(new AddressBean[] {new AddressBean("mock-test")})
           .setSqlQuery("select * from wrapper")
           .setRawHistorySize("2")
           .setInputStream(is);
   ss1.setSamplingRate(1);
   assertTrue(ss1.validate());
   is.setSources(ss1);
   assertTrue(is.validate());
   sensorConfig.setInputStreams(is);
   assertTrue(sensorConfig.validate());
 }
コード例 #2
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();
  }
コード例 #3
0
  @Test
  public void testOutOfOrderData() throws SQLException, InterruptedException {
    MockWrapper wrapper = new MockWrapper();
    sm.executeCreateTable(wrapper.getDBAliasInStr(), wrapper.getOutputFormat(), true);
    AddressBean addressBean = new AddressBean("test");
    wrapper.setActiveAddressBean(addressBean);
    assertTrue(wrapper.initialize());
    InputStream is = new InputStream();

    StreamSource ss =
        new StreamSource()
            .setAlias("my-stream")
            .setAddressing(new AddressBean[] {addressBean})
            .setSqlQuery("select * from wrapper")
            .setRawHistorySize("1")
            .setInputStream(is);
    ss.setSamplingRate(1);
    ss.setWrapper(wrapper);
    assertTrue(ss.validate());

    StreamElement se =
        new StreamElement(wrapper.getOutputFormat(), new Serializable[] {1000}, 1000L);
    assertTrue(wrapper.insertIntoWrapperTable(se));
    se = new StreamElement(wrapper.getOutputFormat(), new Serializable[] {2000}, 2000L);
    assertTrue(wrapper.insertIntoWrapperTable(se));
    se = new StreamElement(wrapper.getOutputFormat(), new Serializable[] {1500}, 1500L);
    assertFalse(wrapper.insertIntoWrapperTable(se));

    wrapper.releaseResources();
  }
コード例 #4
0
  @Test
  public void testReloadingVirtualSensor()
      throws InstantiationException, IllegalAccessException, SQLException {
    VSensorLoader loader = new VSensorLoader();
    InputStream is = new InputStream();
    StreamSource ss =
        new StreamSource()
            .setAlias("my-stream1")
            .setAddressing(addressing)
            .setSqlQuery("select * from wrapper")
            .setRawHistorySize("2")
            .setInputStream(is);
    ss.setSamplingRate(1);
    assertTrue(ss.validate());
    //		assertTrue(loader.prepareStreamSource(is,ss));
    assertTrue(sm.tableExists(ss.getWrapper().getDBAliasInStr()));
    assertTrue(sm.tableExists(ss.getUIDStr()));
    assertFalse(is.getRenamingMapping().isEmpty());
    loader.releaseStreamSource(ss);
    assertTrue(is.getRenamingMapping().isEmpty());
    assertFalse(sm.tableExists(ss.getUIDStr()));
    assertFalse(ss.getWrapper().isActive());
    assertFalse(sm.tableExists(ss.getWrapper().getDBAliasInStr()));
    assertTrue(is.getRenamingMapping().isEmpty());
    ss =
        new StreamSource()
            .setAlias("my-stream1")
            .setAddressing(addressing)
            .setSqlQuery("select * from wrapper")
            .setRawHistorySize("2")
            .setInputStream(is);
    ss.setSamplingRate(1);
    //		assertTrue(loader.prepareStreamSource(is,ss));

  }
コード例 #5
0
 @Test
 public void testOneInputStreamUsingTwoStreamSources()
     throws InstantiationException, IllegalAccessException, SQLException {
   VSensorLoader loader = new VSensorLoader();
   InputStream is = new InputStream();
   StreamSource ss1 =
       new StreamSource()
           .setAlias("my-stream1")
           .setAddressing(new AddressBean[] {new AddressBean("mock-test")})
           .setSqlQuery("select * from wrapper")
           .setRawHistorySize("2")
           .setInputStream(is);
   ss1.setSamplingRate(1);
   assertTrue(ss1.validate());
   //		assertTrue(loader.prepareStreamSource(is,ss1));
   StreamSource ss2 =
       new StreamSource()
           .setAlias("my-stream2")
           .setAddressing(new AddressBean[] {new AddressBean("mock-test")})
           .setSqlQuery("select * from wrapper")
           .setRawHistorySize("20")
           .setInputStream(is);
   ss2.setSamplingRate(1);
   assertTrue(ss2.validate());
   //		assertTrue(loader.prepareStreamSource(is,ss2));
   ss1.getWrapper().releaseResources();
   assertFalse(sm.tableExists(ss1.getWrapper().getDBAliasInStr()));
 }