Package xbird.engine.request

Examples of xbird.engine.request.QueryRequest


    @Test
    public void testExecuteQueryCallback() throws RemoteException, InterruptedException {
        final XQEngineClient engine = new XQEngineClient("//" + bindHost + ":1099/xbird/srv-01");

        final QueryRequest request1 = new QueryRequest("1+2", ReturnType.STRING);
        request1.setReplyPattern(ReplyPattern.CALLBACK);
        CallbackDetector callback = new CallbackDetector();
        Assert.assertNull(engine.execute(request1, callback));

        synchronized(callback) {
            callback.wait();
View Full Code Here


    @Test
    public void testExecuteQuery() throws RemoteException, UnknownHostException {
        XQEngine engine = new XQEngineClient("//" + bindHost + ":1099/xbird/srv-01");

        QueryRequest request1 = new QueryRequest("1+2", ReturnType.STRING);
        Object result1 = engine.execute(request1);
        Assert.assertEquals("3", result1);

        QueryRequest request2 = new QueryRequest("1+4");
        Object result2 = engine.execute(request2);
        Assert.assertEquals(new XInteger(5), result2);
    }
View Full Code Here

    @Test
    public void testExecuteQueryRemoteSequence() throws RemoteException, UnknownHostException {
        XQEngine engine = new XQEngineClient("//" + bindHost + ":1099/xbird/srv-01");

        QueryRequest request1 = new QueryRequest("1+2", ReturnType.REMOTE_SEQUENCE);

        Object result1 = engine.execute(request1);
        RemoteSequence remoteSequence = (RemoteSequence) result1;

        Assert.assertFalse(remoteSequence.isEmpty());
View Full Code Here

    @Test
    public void testExecuteQueryPoll() throws RemoteException, InterruptedException {
        XQEngine engine = new XQEngineClient("//" + bindHost + ":1099/xbird/srv-01");

        QueryRequest request1 = new QueryRequest("1+2", ReturnType.STRING);
        request1.setReplyPattern(ReplyPattern.POLL);
        // not send
        Assert.assertNull(engine.poll(request1));
        // send#1
        Assert.assertNull(engine.execute(request1));
        // poll#1            
        Thread.sleep(3000);
        Assert.assertEquals("3", engine.poll(request1));
        // after polled
        Assert.assertNull(engine.poll(request1));
        // send#2
        QueryRequest request2 = new QueryRequest("1+4");
        request2.setReplyPattern(ReplyPattern.POLL);
        Assert.assertNull(engine.execute(request2));
        // poll#2
        Thread.sleep(3000);
        Assert.assertEquals(new XInteger(5), engine.poll(request2));
    }
View Full Code Here

    @Test
    public void testExecuteQueryPollOutOfOrder() throws RemoteException, InterruptedException {
        XQEngine engine = new XQEngineClient("//" + bindHost + ":1099/xbird/srv-01");

        QueryRequest request1 = new QueryRequest("1+2", ReturnType.STRING);
        request1.setReplyPattern(ReplyPattern.POLL);
        // not send
        Assert.assertNull(engine.poll(request1));
        // send#2
        QueryRequest request2 = new QueryRequest("1+4");
        request2.setReplyPattern(ReplyPattern.POLL);
        Assert.assertNull(engine.execute(request2));

        // send#1
        Assert.assertNull(engine.execute(request1));
        // poll#1
View Full Code Here

    private void executeAt(Reader reader, Writer writer, String remoteEndpoint)
            throws XQueryException, IOException {
        XQEngine engine = new XQEngineClient(remoteEndpoint);
        String query = IOUtils.toString(reader);
        QueryRequest request = new QueryRequest(query, ReturnType.ASYNC_REMOTE_SEQUENCE);
        final Sequence<Item> resultSeq;
        try {
            resultSeq = (Sequence<Item>) engine.execute(request);
        } catch (RemoteException e) {
            throw new XQueryException("failed to execute a query", e);
View Full Code Here

    @Test(dataProvider = "scenario01", invocationCount = 1, threadPoolSize = 1)
    public void scenario01(String remoteEndpoint, String fileName) throws FileNotFoundException,
            IOException, XQueryException {
        XQEngine engine = new XQEngineClient(remoteEndpoint);
        String query = IOUtils.toString(new FileInputStream(fileName));
        QueryRequest request = new QueryRequest(query, ReturnType.ASYNC_REMOTE_SEQUENCE);
        Sequence<Item> resultSeq = (Sequence<Item>) engine.execute(request);
        Writer writer = new FastBufferedWriter(new OutputStreamWriter(System.out), 4096);
        SAXWriter saxwr = new SAXWriter(writer, "UTF-8");
        Serializer ser = new SAXSerializer(saxwr, writer);
        ser.emit(resultSeq);
View Full Code Here

        stdbuf.append(" - free(init): " + StringUtils.displayBytesSize(free));
        final StopWatch sw = new StopWatch("[Xbird] " + queryFile);
        queryFile = XMARK_HOME + '/' + queryFile;

        XQEngine engine = new XQEngineClient("//" + bindHost + ":1099/xbird/srv-01");
        QueryRequest request1 = new QueryRequest(IOUtils.toString(new FileInputStream(queryFile)), ReturnType.REMOTE_SEQUENCE);
        request1.setBaseUri(new File(queryFile).toURI());
        Object result1 = engine.execute(request1);
        RemoteSequence remoteSequence = (RemoteSequence) result1;

        StringWriter res_sw = new StringWriter();
        Serializer ser = new SAXSerializer(new SAXWriter(res_sw), res_sw);
View Full Code Here

        final Request request = rc.getRequest();
        final Signature rsig = request.getSignature();
        if(rsig != Signature.QUERY) {
            throw new IllegalStateException("Illegal command is passed to QueryProcessor: " + rsig);
        }
        final QueryRequest queryRequest = (QueryRequest) request;
        final String query = queryRequest.getQuery();
        if(query == null) {
            throw new IllegalStateException("query was null for: " + queryRequest);
        }

        // load shipped variables
        final XQueryModule module = new XQueryModule();
        final ShippedVariable[] vars = queryRequest.getShippedVariables();
        if(vars != null) {
            for(ShippedVariable var : vars) {
                try {
                    module.putVariable(var.getVarName(), var);
                } catch (XQueryException e) {
                    throw new RemoteException("failed to declare shipped variable: " + var, e);
                }
            }
        }

        final XQueryProcessor proccessor = new XQueryProcessor(module);
        try {
            proccessor.parse(query, queryRequest.getBaseUri());
        } catch (XQueryException e) {
            LOG.error("parse failed: \n" + query, e);
            rc.setFault(e);
            _resHandler.onResponse(rc);
            return;
View Full Code Here

        if(LOG.isInfoEnabled()) {
            LOG.info("Invoking remote query at [" + endpoint + "]:\n " + query);
        }

        XQEngineClient client = new XQEngineClient(endpoint);
        QueryRequest request = new QueryRequest(query, RETURN_TYPE);
        StaticContext statEnv = dynEnv.getStaticContext();
        URI baseUri = statEnv.getBaseURI();
        if(baseUri == null) {
            baseUri = statEnv.getSystemBaseURI();
        }
        request.setBaseUri(baseUri);
        prepareVariablesToShip(request, argv, dynEnv);
        final Object result;
        try {
            result = client.execute(request);
        } catch (RemoteException e) {
View Full Code Here

TOP

Related Classes of xbird.engine.request.QueryRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.