Exemplo n.º 1
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));

  }
Exemplo n.º 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();
  }
Exemplo n.º 3
0
 public Connection getPersistantConnection(VSensorConfig config) throws Exception {
   StorageManager sm = Main.getStorage(config);
   Connection c = connections.get(sm);
   if (c == null) {
     c = sm.getConnection();
     c.setReadOnly(true);
     connections.put(sm, c);
   }
   return c;
 }
Exemplo n.º 4
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()));
 }
Exemplo n.º 5
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();
  }