Package xbird.engine

Examples of xbird.engine.XQEngineClient


        super(XQEngineClientTest.class.getName());
    }

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

        CommandRequest request1 = new CommandRequest(new String[] { "import", "document",
                "C:/Software/xmark/xmark001.xml" });
        request1.setBaseCollection("/xmark");
        Object result1 = engine.execute(request1);
        Assert.assertEquals(Boolean.TRUE, result1);
    }
View Full Code Here


        Assert.assertEquals(Boolean.TRUE, result1);
    }

    @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

        Assert.assertEquals(new XInteger(5), result2);
    }

    @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());
        IFocus<Item> focus = remoteSequence.iterator();
        Assert.assertEquals(new XInteger(3), focus.next());
View Full Code Here

        Assert.assertFalse(focus.hasNext());
    }

    @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

        Assert.assertEquals(new XInteger(5), engine.poll(request2));
    }

    @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
        Thread.sleep(3000);
        Assert.assertEquals("3", engine.poll(request1));
        // after polled
        Assert.assertNull(engine.poll(request1));

        // poll#2
        Thread.sleep(3000);
        Assert.assertEquals(new XInteger(5), engine.poll(request2));
    }
View Full Code Here

        Assert.assertEquals(new XInteger(5), engine.poll(request2));
    }

    @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

        return saxwr;
    }

    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);
        }

        SAXWriter saxwr = prepareSAXWriter(writer);
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);
        writer.flush();
View Full Code Here

            final XQExpression compiledExpr;
            if(analyzedEndpoint instanceof LiteralExpr) {// distributed compile                
                LiteralExpr epLiteral = (LiteralExpr) analyzedEndpoint;
                String endpoint = epLiteral.getValue().stringValue();

                final XQEngineClient client = new XQEngineClient(endpoint);
                final CompileRequest request = new CompileRequest(_queryExpr);

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

                // invokes remote compilation
                final Object result;
                try {
                    result = client.execute(request);
                } catch (RemoteException e) {
                    throw new XQueryException(e.getMessage(), e.getCause());
                } finally {
                    try {
                        client.close();
                    } catch (RemoteException e) {
                        LOG.warn("shutdown failed for `" + endpoint + '\'', e);
                    }
                }
View Full Code Here

            throws XQueryException {
        if(LOG.isDebugEnabled()) {
            LOG.debug("Invoking remote execution at [" + endpoint + "]:\n "
                    + request.getCompiledExpression());
        }
        final XQEngineClient client = new XQEngineClient(endpoint);
        final Object result;
        try {
            result = client.execute(request);
        } catch (RemoteException e) {
            throw new XQueryException(e.getMessage(), e.getCause());
        } finally {
            try {
                client.close();
            } catch (RemoteException e) {
                LOG.warn("shutdown failed for `" + endpoint + '\'', e);
            }
        }
        Sequence resultSeq = (Sequence) result;
View Full Code Here

TOP

Related Classes of xbird.engine.XQEngineClient

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.