Package net.jini.jeri

Examples of net.jini.jeri.OutboundRequestIterator


     */
    private void openClientConnection(final Endpoint ep) {
        Thread t = new Thread(new Runnable() {
            public void run() {
                try {
                    OutboundRequestIterator it = ep.newRequest(
                        InvocationConstraints.EMPTY);
                    OutboundRequest or = it.next();
                    final InputStream is = or.getResponseInputStream();
                    Thread input = new Thread(new Runnable() {
                        public void run() {
                            try {
                                byte[] bytes = new byte[2];
View Full Code Here


     */
    private void openClientConnection(final Endpoint ep) {
        Thread t = new Thread(new Runnable() {
            public void run() {
                try {
                    OutboundRequestIterator it = ep.newRequest(
                        InvocationConstraints.EMPTY);
                    OutboundRequest or = it.next();
                    OutputStream os = or.getRequestOutputStream();
                    byte[] bytes = new byte[expectedBytes];
                    Arrays.fill(bytes,(byte)0x88);
                    os.write(bytes);
                    os.close();
View Full Code Here

        Thread.currentThread().sleep(1000 * 30);
        //Verify OutboundRequest.populateContext(null)
        endpoint = getServerEndpoint();
        context = new SETContext();
        ep = endpoint.enumerateListenEndpoints(context);
        OutboundRequestIterator it =
            ep.newRequest(InvocationConstraints.EMPTY);
        while (it.hasNext()) {
            exceptionThrown = false;
            try {
                it.next().populateContext(null);
            } catch (NullPointerException e) {
                exceptionThrown = true;
            }
            if (!exceptionThrown) {
                throw new TestException("Passing in null to"
View Full Code Here

    public void run() throws Exception {
        int counter = 1;
        Uuid uuid;
        FakeEndpoint endpoint;
        FakeOutboundRequestIterator fakeIterator;
        OutboundRequestIterator iterator;
        BasicObjectEndpoint boe;
        FakeOutputStream fos;
        FakeOutboundRequest request;

        logger.log(Level.FINE,"=================================");
        logger.log(Level.FINE,"test case " + (counter++)
            + ": newCall with null InvocationConstraints");
        logger.log(Level.FINE,"");

        uuid = UuidFactory.create(1,2);
        endpoint = new FakeEndpoint(new FakeOutboundRequestIterator(null));
        boe = new BasicObjectEndpoint(endpoint,uuid,false);
        try {
            boe.newCall(null);
            throw new AssertionError("newCall(null) should fail");
        } catch (NullPointerException ignore) {}

        for (int i = 0; i < cases.length; i++) {
            logger.log(Level.FINE,"=================================");
            Throwable nextException = cases[i];
            logger.log(Level.FINE,"test case " + (counter++)
                + ": nextException:" + nextException);
            logger.log(Level.FINE,"");

            // Test Case: OutboundRequestIterator.next throws exception

            uuid = UuidFactory.create(1,2);
            fakeIterator = new FakeOutboundRequestIterator(null);
            fakeIterator.setNextException(nextException);
            endpoint = new FakeEndpoint(fakeIterator);
            boe = new BasicObjectEndpoint(endpoint,uuid,false);

            iterator = boe.newCall(InvocationConstraints.EMPTY);
            try {
                iterator.next();
                throw new AssertionError("next() should fail");
            } catch (Throwable caught) {
                assertion(nextException.equals(caught),
                    caught.toString());
            }

            // Test Case: Uuid.write throws exception

            fos = new FakeOutputStream(nextException);
            request = new FakeOutboundRequest();
            request.setRequestOutputStream(fos);
            fakeIterator = new FakeOutboundRequestIterator(request);
            endpoint = new FakeEndpoint(fakeIterator);
            boe = new BasicObjectEndpoint(endpoint,uuid,false);

            iterator = boe.newCall(InvocationConstraints.EMPTY);
            try {
                iterator.next();
                throw new AssertionError("next() should fail");
            } catch (Throwable caught) {
                assertion(nextException.equals(caught),
                    caught.toString());
            }
View Full Code Here

        GetDeliveryContext lc = new GetDeliveryContext(dispatcher);
        Endpoint e =
            se.enumerateListenEndpoints(lc);
        dispatcher.reject();
        try {
            OutboundRequestIterator ori =
                e.newRequest(InvocationConstraints.EMPTY);
            while (ori.hasNext()){
                OutboundRequest or = ori.next();
                ObjectOutputStream oos = new ObjectOutputStream(
                    or.getRequestOutputStream());
                oos.writeInt(1);
                oos.close();
            }
        } catch (Exception e2) {
            //Expected exception
            log.finest("Expected exception " + e2.getMessage());
        }
        if (dispatcher.dispatchCalled()!=-1){
            throw new TestException("Exception from the "
                + "dispatcher was not propagated");
        }
        dispatcher.accept();
        try {
            OutboundRequestIterator ori =
                e.newRequest(InvocationConstraints.EMPTY);
            while (ori.hasNext()) {
               OutboundRequest or = ori.next();
               ObjectOutputStream oos = new ObjectOutputStream(
               or.getRequestOutputStream());
               oos.writeInt(2);
               oos.close();
            }
View Full Code Here

        Uuid uuid = UuidFactory.create(1,2);
        FakeOutboundRequest request = new FakeOutboundRequest();
        BasicObjectEndpoint boe = new BasicObjectEndpoint(
             new FakeEndpoint(new FakeOutboundRequestIterator(request)),
             uuid,false);
        OutboundRequestIterator iterator =
            boe.newCall(InvocationConstraints.EMPTY);

        logger.log(Level.FINE,"=================================");
        logger.log(Level.FINE,"test case " + (counter++)
            + ": hasNext returns true");
        logger.log(Level.FINE,"");

        assertion(iterator.hasNext() == true);

        logger.log(Level.FINE,"=================================");
        logger.log(Level.FINE,"test case " + (counter++)
            + ": next returns correct OutboundRequest");
        logger.log(Level.FINE,"");

        assertion(iterator.next() == request);

        logger.log(Level.FINE,"=================================");
        logger.log(Level.FINE,"test case " + (counter++)
            + ": uuid writen to OutboundRequest output stream");
        logger.log(Level.FINE,"");

        Uuid writtenUuid = UuidFactory.read(request.getRequestStream());
        assertion(uuid.equals(writtenUuid));

        logger.log(Level.FINE,"=================================");
        logger.log(Level.FINE,"test case " + (counter++)
            + ": hasNext returns false");
        logger.log(Level.FINE,"");

        assertion(iterator.hasNext() == false);

        logger.log(Level.FINE,"=================================");
        logger.log(Level.FINE,"test case " + (counter++)
            + ": next throws NoSuchElementException");
        logger.log(Level.FINE,"");

        try {
            iterator.next();
            throw new AssertionError("next() should fail");
        } catch (NoSuchElementException ignore) {
        }
    }
View Full Code Here

     */
    private void openClientConnection(final Endpoint ep) {
        Thread t = new Thread(new Runnable() {
            public void run() {
                try {
                    OutboundRequestIterator it = ep.newRequest(
                        InvocationConstraints.EMPTY);
                    OutboundRequest or = it.next();
                    final InputStream is = or.getResponseInputStream();
                    Thread input = new Thread(new Runnable() {
                        public void run() {
                            try {
                                byte[] bytes = new byte[2];
View Full Code Here

                + " ServerEndpoint.enumerateListenEndpoints is not"
                + " serializable");
        }

        //Verify that an outbound request can be obtained from the Endpoint
        OutboundRequestIterator ori =
            e.newRequest(InvocationConstraints.EMPTY);
        int response = 0;
        while (ori.hasNext()) {
            //Verify that the outbound request can be used to communicate
            //with the server side of the connection
            OutboundRequest or = ori.next();
            ObjectOutputStream oos =
                new ObjectOutputStream(or.getRequestOutputStream());
            oos.writeInt(this.hashCode());
            oos.close();
            ObjectInputStream ois = new ObjectInputStream(
                or.getResponseInputStream());
            response = ois.readInt();
            ois.close();
            //Verify UnsupportedOperationException
            ArrayList al = new ArrayList();
            al.add(new Object());
            Collection uc = Collections.unmodifiableCollection(al);
            exceptionThrown = false;
            try {
                uc.add(new Object());
                //This is an implementation specific check
                //comment code line above this comment if implementation
                //is expected to populate the passed in context
                or.populateContext(uc);
            } catch (UnsupportedOperationException uoe) {
                //This exception would only occur if one of the
                //JERI layers attempts to write context information
                //to the collection
                exceptionThrown = true;
            }
            if (!exceptionThrown){
                throw new TestException("Passing an unmodifiable"
                    + " collection to populateContext does not result"
                    + " in UnsupportedOperationException");
            }
            //Verify idempotency of input/output streams
            InputStream i1 = or.getResponseInputStream();
            InputStream i2 = or.getResponseInputStream();
            OutputStream o1 = or.getRequestOutputStream();
            OutputStream o2 = or.getRequestOutputStream();
            if (o1!=o2||i1!=i2) {
                throw new TestException("Idempotency of streams"
                    + " is not maintained");
            }
        }

        //Verify NoSuchElementException
        exceptionThrown = false;
        try {
            ori.next();
        } catch (NoSuchElementException nse) {
            exceptionThrown = true;
        }
        if (!exceptionThrown) {
            throw new TestException("Calling next on an iterator"
                + " that has returned false from hasNext does not throw"
                + " NoSuchElementException");
        }

        Iterator it = endpoints.iterator();
        while(it.hasNext()) {
            EndpointHolder eph = (EndpointHolder) it.next();
            SETRequestHandler rh = (SETRequestHandler)
                eph.getRequestHandler();
            if (response != rh.hashCode()){
                throw new TestException("The response received"
                    + "does not match the response sent by the server"
                    + "side of the connection.  Server sent "
                    + rh.hashCode() + ", but the client got " + response);
            }
            ArrayList requests = rh.getRequests();
            if (requests.size()!=1){
                throw new TestException("The RequestDisptcher"
                    + " received the incorrect number of requests.  "
                    + "Expected 1 and received " + requests.size());
            }
            Iterator requestIterator = requests.iterator();
            while (requestIterator.hasNext()){
                Integer value = (Integer) requestIterator.next();
                if (value.intValue()!=this.hashCode()){
                    throw new TestException("The data read from"
                        + " the InboundRequest does not match the data"
                        + " written to the OutboundRequest.  Wrote "
                        + this.hashCode() + " read " + value);
                }
            }
            ServerEndpoint.ListenHandle lh = eph.getListenHandle();
            //Close the listen operation
            lh.close();
        }
        //Verify that new requests are not received after close has
        //been called on the ListenHandle
        try {
            ori = e.newRequest(InvocationConstraints.EMPTY);
            while (ori.hasNext()) {
                OutboundRequest or = ori.next();
                ObjectOutputStream oos =
                    new ObjectOutputStream(or.getRequestOutputStream());
                oos.writeInt(this.hashCode());
                oos.close();
            }
View Full Code Here

        boolean integritySupported = ((Boolean)getConfigObject(
            Boolean.class, "integritySupported")).booleanValue();
        //Verify conflicting constraints
        boolean exceptionThrown = false;
        try {
            OutboundRequestIterator it = endpoint
                .newRequest(conflictingConstraints);
            while (it.hasNext()) {
                OutboundRequest or = it.next();
                log.finest("Obtained " + or + " from " + endpoint);
            }
        } catch (UnsupportedConstraintException e){
            exceptionThrown = true;
        }
        if (!exceptionThrown) {
            throw new TestException("Conflicting constraints"
                + " did not generate an UnsupportedConstraintsException"
                + " for " + endpoint + ".newRequest()");
        }
        //Verify unsupported constraints
        exceptionThrown = false;
        try {
            OutboundRequestIterator it = endpoint
                .newRequest(conflictingConstraints);
            while (it.hasNext()) {
                OutboundRequest or = it.next();
                log.finest("Obtained " + or + " from " + endpoint);
            }
        } catch (UnsupportedConstraintException e){
            exceptionThrown = true;
        }
View Full Code Here

     */
    private void openClientConnection(final Endpoint ep) {
        Thread t = new Thread(new Runnable() {
            public void run() {
                try {
                    OutboundRequestIterator it = ep.newRequest(
                        InvocationConstraints.EMPTY);
                    OutboundRequest or = it.next();
                    final InputStream is = or.getResponseInputStream();
                    //read input from the test server
                    Thread input = new Thread(new Runnable() {
                        public void run() {
                            try {
View Full Code Here

TOP

Related Classes of net.jini.jeri.OutboundRequestIterator

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.