@Test public void testPrepareWrapper() throws ClassNotFoundException, InstantiationException, IllegalAccessException { VSensorLoader loader = new VSensorLoader(); MockWrapper wrapper = (MockWrapper) loader.findWrapper(addressing[0]); assertNotNull(wrapper); }
@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)); }
private Main() throws Exception { ValidityTools.checkAccessibilityOfFiles( DEFAULT_GSN_LOG4J_PROPERTIES, WrappersUtil.DEFAULT_WRAPPER_PROPERTIES_FILE, DEFAULT_GSN_CONF_FILE); ValidityTools.checkAccessibilityOfDirs(DEFAULT_VIRTUAL_SENSOR_DIRECTORY); PropertyConfigurator.configure(Main.DEFAULT_GSN_LOG4J_PROPERTIES); // initializeConfiguration(); try { controlSocket = new GSNController(null, gsnControllerPort); containerConfig = loadContainerConfiguration(); updateSplashIfNeeded( new String[] { "GSN is starting at port:" + containerConfig.getContainerPort(), "All GSN logs are available at: logs/gsn.log" }); System.out.println( "Global Sensor Networks (GSN) is Starting on port " + containerConfig.getContainerPort() + "..."); System.out.println("The logs of GSN server are available in logs/gsn.log file."); System.out.println("To Stop GSN execute the gsn-stop script."); } catch (FileNotFoundException e) { logger.error( new StringBuilder() .append("The the configuration file : conf/gsn.xml") .append(" doesn't exist.") .toString()); logger.error(e.getMessage()); logger.error("Check the path of the configuration file and try again."); if (logger.isDebugEnabled()) logger.debug(e.getMessage(), e); throw new Exception(e); } int maxDBConnections = System.getProperty("maxDBConnections") == null ? DEFAULT_MAX_DB_CONNECTIONS : Integer.parseInt(System.getProperty("maxDBConnections")); int maxSlidingDBConnections = System.getProperty("maxSlidingDBConnections") == null ? DEFAULT_MAX_DB_CONNECTIONS : Integer.parseInt(System.getProperty("maxSlidingDBConnections")); int maxServlets = System.getProperty("maxServlets") == null ? DEFAULT_JETTY_SERVLETS : Integer.parseInt(System.getProperty("maxServlets")); // Init the AC db connection. if (Main.getContainerConfig().isAcEnabled() == true) { ConnectToDB.init( containerConfig.getStorage().getJdbcDriver(), containerConfig.getStorage().getJdbcUsername(), containerConfig.getStorage().getJdbcPassword(), containerConfig.getStorage().getJdbcURL()); } mainStorage = StorageManagerFactory.getInstance( containerConfig.getStorage().getJdbcDriver(), containerConfig.getStorage().getJdbcUsername(), containerConfig.getStorage().getJdbcPassword(), containerConfig.getStorage().getJdbcURL(), maxDBConnections); // StorageConfig sc = containerConfig.getSliding() != null ? containerConfig.getSliding().getStorage() : containerConfig.getStorage(); windowStorage = StorageManagerFactory.getInstance( sc.getJdbcDriver(), sc.getJdbcUsername(), sc.getJdbcPassword(), sc.getJdbcURL(), maxSlidingDBConnections); // validationStorage = StorageManagerFactory.getInstance( "org.h2.Driver", "sa", "", "jdbc:h2:mem:validator", Main.DEFAULT_MAX_DB_CONNECTIONS); if (logger.isInfoEnabled()) logger.info("The Container Configuration file loaded successfully."); try { logger.debug( "Starting the http-server @ port: " + containerConfig.getContainerPort() + " (maxDBConnections: " + maxDBConnections + ", maxSlidingDBConnections: " + maxSlidingDBConnections + ", maxServlets:" + maxServlets + ")" + " ..."); Server jettyServer = getJettyServer( getContainerConfig().getContainerPort(), getContainerConfig().getSSLPort(), maxServlets); jettyServer.start(); logger.debug("http-server running @ port: " + containerConfig.getContainerPort()); } catch (Exception e) { throw new Exception( "Start of the HTTP server failed. The HTTP protocol is used in most of the communications: " + e.getMessage(), e); } VSensorLoader vsloader = VSensorLoader.getInstance(DEFAULT_VIRTUAL_SENSOR_DIRECTORY); controlSocket.setLoader(vsloader); String msrIntegration = "gsn.msr.sensormap.SensorMapIntegration"; try { vsloader.addVSensorStateChangeListener( (VSensorStateChangeListener) Class.forName(msrIntegration).newInstance()); } catch (Exception e) { logger.warn("MSR Sensor Map integration is disabled."); } vsloader.addVSensorStateChangeListener(new SQLValidatorIntegration(SQLValidator.getInstance())); vsloader.addVSensorStateChangeListener(DataDistributer.getInstance(LocalDeliveryWrapper.class)); vsloader.addVSensorStateChangeListener(DataDistributer.getInstance(PushDelivery.class)); vsloader.addVSensorStateChangeListener(DataDistributer.getInstance(RestDelivery.class)); ContainerImpl.getInstance() .addVSensorDataListener(DataDistributer.getInstance(LocalDeliveryWrapper.class)); ContainerImpl.getInstance() .addVSensorDataListener(DataDistributer.getInstance(PushDelivery.class)); ContainerImpl.getInstance() .addVSensorDataListener(DataDistributer.getInstance(RestDelivery.class)); vsloader.startLoading(); }