/** * Runs the stress test. * * @param clients number of clients * @param runs number of runs per client * @throws Exception exception */ private void run(final int clients, final int runs) throws Exception { // run server instance server = createServer(); // create test database try (final ClientSession cs = createClient()) { cs.execute("create db test <test/>"); // run clients final Client[] cl = new Client[clients]; for (int i = 0; i < clients; ++i) cl[i] = new Client(runs, i % 2 == 0); for (final Client c : cl) c.start(); for (final Client c : cl) c.join(); // drop database and stop server cs.execute("drop db test"); } stopServer(server); }
/** * Creates a WatchService and registers the given directory. * * @param dir root of file hierarchy to monitor * @param recursive whether to watch recursively * @param v call back reference to produce FSML output on events * @throws IOException in case of failure */ public FSWatch(final Path dir, final boolean recursive, final FSMLVisitor v) throws IOException { this.watcher = FileSystems.getDefault().newWatchService(); this.keys = new HashMap<WatchKey, Path>(); this.recursive = recursive; this.fsml = v; if (recursive) { System.err.format("%s Scanning %s ...\n", NAME, dir); registerAll(dir); System.err.println(NAME + " Done."); } else { register(dir); } // enable trace after initial registration this.trace = true; session = new ClientSession(Conf.DBHOST, Conf.DBPORT, Conf.DBUSER, Conf.DBPASS); try { String r = session.execute("open " + Conf.DBNAME); System.err.print(NAME + " " + r + session.info()); } catch (BaseXException e) { e.printStackTrace(); } }
@Override public void run() { try { // Perform query session.execute("xquery " + QUERY); session.close(); } catch (final Exception ex) { ex.printStackTrace(); } }
@Override public void run() { try { // Perform some queries for (int i = 0; i < runs; ++i) { final String qu = read ? "count(db:open('test'))" : "db:add('test', <a/>, 'test.xml', map { 'intparse': true() })"; session.execute("xquery " + qu); } session.close(); } catch (final Exception ex) { ex.printStackTrace(); } }
@Override protected void execute(final Command cmd, final OutputStream os) throws IOException { execute(cmd.toString(), os); }
/** * Constructor. * * @param runs number of runs * @param read read flag * @throws Exception exception */ Client(final int runs, final boolean read) throws Exception { this.runs = runs; this.read = read; session = createClient(); session.execute("set autoflush false"); }