Package net.jini.space

Examples of net.jini.space.JavaSpace05


         * Writes entries to a space with predefined delay
         */
        public void run() {
            try {
                Thread.sleep(delay);
                JavaSpace05 space05 = (JavaSpace05) space;
                space05.write(entries, txn, leases);
            catch (Exception e) {
                this.e = e;
            }
        }
View Full Code Here


    public void run() throws Exception {
        Transaction txn = getTransaction();
        ArrayList registrations = new ArrayList();

        TestEventListener05.setConfiguration(config.getConfiguration());
        JavaSpace05 space05 = (JavaSpace05) space;
        reset(txn);

        TestEventListener05 testEventListener0 = new TestEventListener05();
        templates.add((SimpleEntry) sampleEntry1.clone());
        EventRegistration er0 = space05.registerForAvailabilityEvent(templates,
                txn, true, testEventListener0, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        final long gotER0Timestamp = System.currentTimeMillis();
        List notifications = testEventListener0.getNotifications();
        expectedResult.add(sampleEntry1)// this entry is to trigger the event
        space.write(sampleEntry1, txn, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing one entry to trigger an event");
        registrations.add(er0);
        reset(txn);

        TestEventListener05 testEventListener1 = new TestEventListener05();
        templates.add((SimpleEntry) sampleEntry1.clone());
        templates.add((SimpleEntry) sampleEntry2.clone());
        EventRegistration er1 = space05.registerForAvailabilityEvent(templates,
                txn, true, testEventListener1, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        notifications = testEventListener1.getNotifications();
        expectedResult.add(sampleEntry1);
        expectedResult.add(sampleEntry2);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing 2 entries to trigger 2 events");
        registrations.add(er1);
        reset(txn);

        TestEventListener05 testEventListener2 = new TestEventListener05();
        templates.add(new SimpleEntry(null, 2));
        EventRegistration er2 = space05.registerForAvailabilityEvent(templates,
                txn, true, testEventListener2, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        notifications = testEventListener2.getNotifications();
        expectedResult.add(sampleEntry2);
        expectedResult.add(sampleEntry3);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing 2 entries to trigger 2 events "
                           + "(with single template)");
        registrations.add(er2);
        reset(txn);

        TestEventListener05 testEventListener3 = new TestEventListener05();
        templates.add(new SimpleEntry(null, null));
        EventRegistration er3 = space05.registerForAvailabilityEvent(templates,
                txn, true, testEventListener3, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        notifications = testEventListener3.getNotifications();
        expectedResult.add(sampleEntry1);
        expectedResult.add(sampleEntry2);
        expectedResult.add(sampleEntry3);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing 3 entries to trigger 3 events "
                           + "(with single template)");
        registrations.add(er3);
        reset(txn);

        TestEventListener05 testEventListener4 = new TestEventListener05();
        templates.add(null);
        EventRegistration er4 = space05.registerForAvailabilityEvent(templates,
                txn, true, testEventListener4, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        notifications = testEventListener4.getNotifications();
        expectedResult.add(sampleEntry1);
        expectedResult.add(sampleEntry2);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing 2 entries to trigger 2 events "
                           + "(with null template)");
        registrations.add(er4);
        reset(txn);

        TestEventListener05 testEventListener5 = new TestEventListener05();
        templates.add(null);
        EventRegistration er5 = space05.registerForAvailabilityEvent(templates,
                txn, true, testEventListener5, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        notifications = testEventListener5.getNotifications();
        expectedResult.add(sampleEntry1);
        expectedResult.add(sampleEntry1);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry1, txn, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing 2 duplicate entries to trigger 2 events "
                           + "(with null template)");

        /*
         * not adding this as a registration for such set
         * of templates (null) already exists
         */
        //registrations.add(er5);
        reset(txn);

        TestEventListener05 testEventListener6 = new TestEventListener05();
        templates.add(null);
        templates.add(new SimpleEntry(null, null));
        templates.add((SimpleEntry) sampleEntry2.clone());
        templates.add((SimpleEntry) sampleEntry3.clone());
        templates.add(new SimpleEntry(null, 2));
        EventRegistration er6 = space05.registerForAvailabilityEvent(templates,
                txn, true, testEventListener6, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        notifications = testEventListener6.getNotifications();
        expectedResult.add(sampleEntry2);
        expectedResult.add(sampleEntry3);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing 2 entries to trigger 2 events " +
                           "(with multiple matching templates)");
        registrations.add(er6);
        reset(txn);

        /*
         * Section below is the same as above but
         * with visibilityOnly flag set to false.
         * "a" stands for availability.
         */
        TestEventListener05 testEventListener0a = new TestEventListener05();
        templates.add((SimpleEntry) sampleEntry1.clone());
        EventRegistration er0a = space05.registerForAvailabilityEvent(
                templates, txn, false,
                testEventListener0a, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        notifications = testEventListener0a.getNotifications();
        expectedResult.add(sampleEntry1)// this entry is to trigger the event
        space.write(sampleEntry1, txn, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing one entry to trigger an event");
        registrations.add(er0a);
        reset(txn);

        TestEventListener05 testEventListener1a = new TestEventListener05();
        templates.add((SimpleEntry) sampleEntry1.clone());
        templates.add((SimpleEntry) sampleEntry2.clone());
        EventRegistration er1a = space05.registerForAvailabilityEvent(
                templates, txn, false,
                testEventListener1a, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        notifications = testEventListener1a.getNotifications();
        expectedResult.add(sampleEntry1);
        expectedResult.add(sampleEntry2);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing 2 entries to trigger 2 events");
        registrations.add(er1a);
        reset(txn);

        TestEventListener05 testEventListener2a = new TestEventListener05();
        templates.add(new SimpleEntry(null, 2));
        EventRegistration er2a = space05.registerForAvailabilityEvent(
                templates, txn, false,
                testEventListener2a, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        notifications = testEventListener2a.getNotifications();
        expectedResult.add(sampleEntry2);
        expectedResult.add(sampleEntry3);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing 2 entries to trigger 2 events "
                           + "(with single template)");
        registrations.add(er2a);
        reset(txn);

        TestEventListener05 testEventListener3a = new TestEventListener05();
        templates.add(new SimpleEntry(null, null));
        EventRegistration er3a = space05.registerForAvailabilityEvent(
                templates, txn, false,
                testEventListener3a, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        notifications = testEventListener3a.getNotifications();
        expectedResult.add(sampleEntry1);
        expectedResult.add(sampleEntry2);
        expectedResult.add(sampleEntry3);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing 3 entries to trigger 3 events "
                           + "(with single template)");
        registrations.add(er3a);
        reset(txn);

        TestEventListener05 testEventListener4a = new TestEventListener05();
        templates.add(null);
        EventRegistration er4a = space05.registerForAvailabilityEvent(
                templates, txn, false,
                testEventListener4a, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        notifications = testEventListener4a.getNotifications();
        expectedResult.add(sampleEntry1);
        expectedResult.add(sampleEntry2);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing 2 entries to trigger 2 events "
                           + "(with null template)");
        registrations.add(er4a);
        reset(txn);

        TestEventListener05 testEventListener5a = new TestEventListener05();
        templates.add(null);
        EventRegistration er5a = space05.registerForAvailabilityEvent(
                templates, txn, false,
                testEventListener5a, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        notifications = testEventListener5a.getNotifications();
        expectedResult.add(sampleEntry1);
        expectedResult.add(sampleEntry1);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry1, txn, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing 2 duplicate entries to trigger 2 events "
                           + "(with null template)");

        /*
         * not adding this as a registration for such set
         * of templates (null) already exists
         */
        //registrations.add(er5a);
        reset(txn);

        TestEventListener05 testEventListener6a = new TestEventListener05();
        templates.add(null);
        templates.add(new SimpleEntry(null, null));
        templates.add((SimpleEntry) sampleEntry2.clone());
        templates.add((SimpleEntry) sampleEntry3.clone());
        templates.add(new SimpleEntry(null, 2));
        EventRegistration er6a = space05.registerForAvailabilityEvent(
                templates, txn, false,
                testEventListener6a, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        notifications = testEventListener6a.getNotifications();
        expectedResult.add(sampleEntry2);
        expectedResult.add(sampleEntry3);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing 2 entries to trigger 2 events " +
                           "(with multiple matching templates)");
        registrations.add(er6a);
        reset(txn);

        ArrayList eventIDs = new ArrayList();
        Iterator registrationsItr = registrations.iterator();
        while (registrationsItr.hasNext()) {
            EventRegistration er = (EventRegistration) registrationsItr.next();
            if (er == null) {
                throw new TestException("Event registration is null");
            }
            Long id = new Long(er.getID());
            if (eventIDs.contains(id)) {
                throw new TestException("Event registrations have"
                                        + " identical IDs");
            }
            eventIDs.add(id);
        }

        JavaSpace testSpace = (JavaSpace) er0.getSource();
        space.write(sampleEntry1, txn, leaseForeverTime);
        SimpleEntry entry = (SimpleEntry) testSpace.readIfExists(sampleEntry1,
                                                                 txn,
                                                                 instantTime);
        if (!sampleEntry1.equals(entry)) {
            throw new TestException("EventRegistration.getSource method "
                                    + "does not return a proper "
                                    + "reference to the space");
        }
        reset(txn);

        Lease lease = er0.getLease();
        if (lease.getExpiration() > gotER0Timestamp + leaseForeverTime) {
            throw new TestException(
                    "Lease for EventRegistration expires later than expected");
        }

        txn.commit();

        /*
         * After transaction commited the appropriate event registrations
         * (all in this case) are dropped.
         * Therefore it is assumed that no more notifications will be
         * recieved by appropriate listeners.
         * The expectedResult is empty.
         */
        Thread.sleep(2000);     // let the time for registrations to be dropped
        notifications = testEventListener2.getNotifications();
        notifications.clear(); // clear all the previous notifications
        space.write(sampleEntry2, null, leaseForeverTime);
        space.write(sampleEntry3, null, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing 2 entries to trigger no events " +
                           "(registration dropped)");
        cleanSpace(space);

        txn = getTransaction();
        TestEventListener05 testEventListenerExc = new TestEventListener05();
        templates.add((SimpleEntry) sampleEntry1.clone());
        templates.add("not an Entry");
        try {
            space05.registerForAvailabilityEvent(templates, txn, true,
                    testEventListenerExc, leaseForeverTime,
                    new MarshalledObject("notUsedHere"));
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when a non-null element of tmpls "
                                    + "is not an instance of Entry");
        } catch (IllegalArgumentException e) {}

        templates.clear();
        try {
            space05.registerForAvailabilityEvent(templates, txn, true,
                    testEventListenerExc, leaseForeverTime,
                    new MarshalledObject("notUsedHere"));
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when tmpls is empty");
        } catch (IllegalArgumentException e) {}

        templates.add((SimpleEntry) sampleEntry1.clone());
        try {
            space05.registerForAvailabilityEvent(templates, txn, true,
                    testEventListenerExc, 0,
                    new MarshalledObject("notUsedHere"));
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when leaseDuration is neither positive "
                                    + "nor Lease.ANY (0)");
        } catch (IllegalArgumentException e) {}       

        try {
            space05.registerForAvailabilityEvent(templates, txn, true,
                    testEventListenerExc, Lease.ANY - 1,
                    new MarshalledObject("notUsedHere"));
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when leaseDuration is neither positive "
                                    + "nor Lease.ANY (Lease.ANY-1)");
        } catch (IllegalArgumentException e) {}

        try {
            space05.registerForAvailabilityEvent(null, txn, true,
                    testEventListenerExc, leaseForeverTime,
                    new MarshalledObject("notUsedHere"));
            throw new TestException("NullPointerException is not thrown "
                                    + "when tmpls is null");
        } catch (NullPointerException e) {}

        try {
            space05.registerForAvailabilityEvent(templates, txn, true,
                    null, leaseForeverTime,
                    new MarshalledObject("notUsedHere"));
            throw new TestException("NullPointerException is not thrown "
                                    + "when listener is null");
        } catch (NullPointerException e) {}

        txn.commit();

        /*
         * Transaction txn is not null and is not usable by the space.
         * templates is not empty
         */
        try {
            space05.registerForAvailabilityEvent(templates, txn, true,
                    testEventListenerExc, leaseForeverTime,
                    new MarshalledObject("notUsedHere"));
            throw new TestException("TransactionException is not thrown when "
                                    + "trying to register for event with with "
                                    + "non-null and not usable by the space "
View Full Code Here

        // first check that space is empty
        if (!checkSpace(space)) {
            throw new TestException("Space is not empty in the beginning.");
        }
        JavaSpace05 space05 = (JavaSpace05) space;

        ArrayList entriesList = new ArrayList();
        entriesList.add(sampleEntry1);
        entriesList.add(sampleEntry2);

        ArrayList leasesList = new ArrayList();
        leasesList.add(new Long(leaseTime1));
        leasesList.add(new Long(leaseTime1));

        space05.write(entriesList, null, leasesList);

        // check that written entries are available in the space
        SimpleEntry resultEntry1 = (SimpleEntry) space05.read(sampleEntry1,
                                                              null, checkTime);
        SimpleEntry resultEntry2 = (SimpleEntry) space05.read(sampleEntry2,
                                                              null, checkTime);


        if (resultEntry1 == null || resultEntry2 == null) {
            throw new TestException("performed write of " + sampleEntry1
                                    + " with " + leaseTime1
                                    + " lease time and "
                                    + sampleEntry2 + " with " + leaseTime2
                                    + " lease time and "
                                    + " written entry(ies) is(are) not "
                                    + "available in the space.");
        }


        /*
         * A new copy of each element will be stored
         * even if there are duplicates
         */
        entriesList.clear();
        entriesList.add(sampleEntry1);
        entriesList.add(sampleEntry1);
        entriesList.add(sampleEntry3);

        leasesList.clear();
        leasesList.add(new Long(leaseTime1));
        leasesList.add(new Long(leaseTime2));
        leasesList.add(new Long(leaseTime2));

        space05.write(entriesList, null, leasesList);

        /*
         * check that entry1 can be taken from the space 3 times,
         * and entries 2 and 3 only once.
         */
        SimpleEntry result = (SimpleEntry) space05.take(sampleEntry1, null,
                                                        checkTime);
        result = (SimpleEntry) space05.take(sampleEntry1, null, checkTime);
        result = (SimpleEntry) space05.take(sampleEntry1, null, checkTime);
        if (result == null) {
            throw new TestException("performed 2-nd and 3-rd write "
                    + "operation for the same " + sampleEntry1
                    + " with " + leaseTime1 + " lease time and "
                    + leaseTime2 + " lease time and all or some "
                    + "of the entries can not be taken");
        }
        result = (SimpleEntry) space05.take(sampleEntry2, null, checkTime);
        if (result == null) {
            throw new TestException(sampleEntry2 + " with " + leaseTime1
                                    + " lease time"
                                    + " is not available in the space.");
        }
        result = (SimpleEntry) space05.take(sampleEntry3, null, checkTime);
        if (result == null) {
            throw new TestException(sampleEntry3 + " with " + leaseTime2
                                    + " lease time"
                                    + " is not available in the space.");
        }

        cleanSpace(space);
        entriesList.clear();
        leasesList.clear();
        try {
            space05.write(entriesList, null, leasesList);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when using empty entries list and "
                                    + "empty lease list");
        } catch (IllegalArgumentException e) {}

        entriesList.add(sampleEntry1);
        try {
            space05.write(entriesList, null, leasesList);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when using empty lease list");
        } catch (IllegalArgumentException e) {}

        entriesList.add(sampleEntry1);          // add the second entry
        leasesList.add(new Long(leaseTime1));   // add the first lease time
        try {
            space05.write(entriesList, null, leasesList);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when using entries list and lease "
                                    + "list of different length");
        } catch (IllegalArgumentException e) {}

        entriesList.clear();
        leasesList.clear();
        entriesList.add(sampleEntry1);
        entriesList.add("not an entry");
        leasesList.add(new Long(leaseTime1));
        leasesList.add(new Long(leaseTime2));
        try {
            space05.write(entriesList, null, leasesList);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when using not instance of Entry "
                                    + "as an element of entries");
        } catch (IllegalArgumentException e) {}

        entriesList.clear();
        leasesList.clear();
        entriesList.add(sampleEntry1);
        entriesList.add(sampleEntry1);
        leasesList.add(new Long(leaseTime1));
        leasesList.add("not a Long");
        try {
            space05.write(entriesList, null, leasesList);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when using not instance of Long "
                                    + "as an element of leaseDurations");
        } catch (IllegalArgumentException e) {}

        entriesList.clear();
        leasesList.clear();
        entriesList.add(sampleEntry1);
        entriesList.add(sampleEntry1);
        leasesList.add(new Long(leaseTime1));
        leasesList.add(new Long(Lease.ANY - 1));
        try {
            space05.write(entriesList, null, leasesList);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when an element of leaseDurations is "
                                    + "a negative value other than Lease.ANY");
        } catch (IllegalArgumentException e) {}

        if (!checkSpace(space)) {
            throw new TestException("Some entries were written to the space "
                                    + "despite write operation threw "
                                    + "IllegalArgumentException");
        }

        entriesList.clear();
        leasesList.clear();
        entriesList.add(sampleEntry1);
        leasesList.add(new Long(leaseTime1));
        try {
            space05.write(null, null, leasesList);
            throw new TestException("NullPointerException is not thrown "
                                    + "when entries list in null");
        } catch (NullPointerException e) {}
        try {
            space05.write(entriesList, null, null);
            throw new TestException("NullPointerException is not thrown "
                                    + "when leaseDurations list in null");
        } catch (NullPointerException e) {}

        entriesList.clear();
        leasesList.clear();
        entriesList.add(sampleEntry1);
        entriesList.add(null);
        leasesList.add(new Long(leaseTime1));
        leasesList.add(new Long(leaseTime1));
        try {
            space05.write(entriesList, null, leasesList);
            throw new TestException("NullPointerException is not thrown "
                                    + "when entries list contains null");
        } catch (NullPointerException e) {}

        entriesList.clear();
        leasesList.clear();
        entriesList.add(sampleEntry1);
        entriesList.add(sampleEntry1);
        leasesList.add(new Long(leaseTime1));
        leasesList.add(null);
        try {
            space05.write(entriesList, null, leasesList);
            throw new TestException("NullPointerException is not thrown "
                                    + "when leaseDurations list contains null");
        } catch (NullPointerException e) {}

        if (!checkSpace(space)) {
View Full Code Here

                               String testName) throws Exception
    {
        if (txn == null) {
            throw new TestException("Transaction is null for test " + testName);
        }
        JavaSpace05 space05 = (JavaSpace05) space;
        Collection result = space05.take(templates, txn, timeout, maxEntries);
        maxEntries -= result.size();
        if (result.size() > 0) {
            while (maxEntries > 0) {
                Collection anyMore = space05.take(templates, txn, 1000,
                                                  maxEntries);
                if (anyMore.size() == 0) break;
                result.addAll(anyMore);
                maxEntries -= anyMore.size();
            }
View Full Code Here

         * Writes entries to a space with predefined delay
         */
        public void run() {
            try {
                Thread.sleep(delay);
                JavaSpace05 space05 = (JavaSpace05) space;
                space05.write(entries, txn, leases);
            catch (Exception e) {
                this.e = e;
            }
        }
View Full Code Here

        // first check that space is empty
        if (!checkSpace(space)) {
            throw new TestException("Space is not empty in the beginning.");
        }
        JavaSpace05 space05 = (JavaSpace05) space;

        ArrayList entriesList = new ArrayList();
        entriesList.add(sampleEntry1);
        entriesList.add(sampleEntry2);

        ArrayList leasesList = new ArrayList();
        leasesList.add(new Long(leaseTime1));
        leasesList.add(new Long(leaseTime1));

        Transaction txn = getTransaction();
        space05.write(entriesList, txn, leasesList);

        // check that written entries are available in the space
        SimpleEntry resultEntry1 = (SimpleEntry) space05.read(sampleEntry1,
                                                              txn, checkTime);
        SimpleEntry resultEntry2 = (SimpleEntry) space05.read(sampleEntry2,
                                                              txn, checkTime);
        txn.commit();
        if (resultEntry1 == null || resultEntry2 == null) {
            throw new TestException("performed write of " + sampleEntry1
                                    + " with " + leaseTime1
                                    + " lease time and "
                                    + sampleEntry2 + " with " + leaseTime2
                                    + " lease time and "
                                    + " written entry(ies) is(are) not "
                                    + "available in the space.");
        }

        /*
         * A new copy of each element will be stored
         * even if there are duplicates
         */
        entriesList.clear();
        entriesList.add(sampleEntry1);
        entriesList.add(sampleEntry1);
        entriesList.add(sampleEntry3);

        leasesList.clear();
        leasesList.add(new Long(leaseTime1));
        leasesList.add(new Long(leaseTime2));
        leasesList.add(new Long(leaseTime2));

        txn = getTransaction();
        space05.write(entriesList, txn, leasesList);

        /*
         * check that entry1 can be taken from the space 3 times,
         * and entries 2 and 3 only once.
         */
        SimpleEntry result = (SimpleEntry) space05.take(sampleEntry1, txn,
                                                        checkTime);
        result = (SimpleEntry) space05.take(sampleEntry1, txn, checkTime);
        result = (SimpleEntry) space05.take(sampleEntry1, txn, checkTime);
        if (result == null) {
            throw new TestException("performed 2-nd and 3-rd write "
                    + "operation for the same " + sampleEntry1
                    + " with " + leaseTime1 + " lease time and "
                    + leaseTime2 + " lease time and all or some "
                    + "of the entries can not be taken");
        }
        result = (SimpleEntry) space05.take(sampleEntry2, txn, checkTime);
        if (result == null) {
            throw new TestException(sampleEntry2 + " with " + leaseTime1
                                    + " lease time"
                                    + " is not available in the space.");
        }
        result = (SimpleEntry) space05.take(sampleEntry3, txn, checkTime);
        if (result == null) {
            throw new TestException(sampleEntry3 + " with " + leaseTime2
                                    + " lease time"
                                    + " is not available in the space.");
        }
        txn.commit();

        cleanSpace(space);
        txn = getTransaction();
        entriesList.clear();
        leasesList.clear();
        try {
            space05.write(entriesList, txn, leasesList);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when using empty entries list and "
                                    + "empty lease list");
        } catch (IllegalArgumentException e) {}

        entriesList.add(sampleEntry1);
        try {
            space05.write(entriesList, txn, leasesList);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when using empty lease list");
        } catch (IllegalArgumentException e) {}

        entriesList.add(sampleEntry1);          // add the second entry
        leasesList.add(new Long(leaseTime1));   // add the first lease time
        try {
            space05.write(entriesList, txn, leasesList);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when using entries list and lease "
                                    + "list of different length");
        } catch (IllegalArgumentException e) {}

        entriesList.clear();
        leasesList.clear();
        entriesList.add(sampleEntry1);
        entriesList.add("not an entry");
        leasesList.add(new Long(leaseTime1));
        leasesList.add(new Long(leaseTime2));
        try {
            space05.write(entriesList, txn, leasesList);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when using not instance of Entry "
                                    + "as an element of entries");
        } catch (IllegalArgumentException e) {}

        entriesList.clear();
        leasesList.clear();
        entriesList.add(sampleEntry1);
        entriesList.add(sampleEntry1);
        leasesList.add(new Long(leaseTime1));
        leasesList.add("not a Long");
        try {
            space05.write(entriesList, txn, leasesList);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when using not instance of Long "
                                    + "as an element of leaseDurations");
        } catch (IllegalArgumentException e) {}

        entriesList.clear();
        leasesList.clear();
        entriesList.add(sampleEntry1);
        entriesList.add(sampleEntry1);
        leasesList.add(new Long(leaseTime1));
        leasesList.add(new Long(Lease.ANY - 1));
        try {
            space05.write(entriesList, txn, leasesList);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when an element of leaseDurations is "
                                    + "a negative value other than Lease.ANY");
        } catch (IllegalArgumentException e) {}

        if (!checkSpace(space, txn)) {
            throw new TestException("Some entries were written to the space "
                                    + "despite write operation threw "
                                    + "IllegalArgumentException");
        }

        entriesList.clear();
        leasesList.clear();
        entriesList.add(sampleEntry1);
        leasesList.add(new Long(leaseTime1));
        try {
            space05.write(null, txn, leasesList);
            throw new TestException("NullPointerException is not thrown "
                                    + "when entries list in null");
        } catch (NullPointerException e) {}
        try {
            space05.write(entriesList, txn, null);
            throw new TestException("NullPointerException is not thrown "
                                    + "when leaseDurations list in null");
        } catch (NullPointerException e) {}

        entriesList.clear();
        leasesList.clear();
        entriesList.add(sampleEntry1);
        entriesList.add(null);
        leasesList.add(new Long(leaseTime1));
        leasesList.add(new Long(leaseTime1));
        try {
            space05.write(entriesList, txn, leasesList);
            throw new TestException("NullPointerException is not thrown "
                                    + "when entries list contains null");
        } catch (NullPointerException e) {}

        entriesList.clear();
        leasesList.clear();
        entriesList.add(sampleEntry1);
        entriesList.add(sampleEntry1);
        leasesList.add(new Long(leaseTime1));
        leasesList.add(null);
        try {
            space05.write(entriesList, txn, leasesList);
            throw new TestException("NullPointerException is not thrown "
                                    + "when leaseDurations list contains null");
        } catch (NullPointerException e) {}

        if (!checkSpace(space,txn)) {
            throw new TestException("Some entries were written to the space "
                                    + "despite write operation threw "
                                    + "NullPointerException");
        }

        txn.commit();

        // transaction txn is not null and is not usable by the space
        entriesList.clear();
        leasesList.clear();
        entriesList.add(sampleEntry1);
        leasesList.add(new Long(leaseTime1));
        try {
            space05.write(entriesList, txn, leasesList);
            throw new TestException("TransactionException is not thrown "
                                    + "when writing to the space with "
                                    + "transaction which is not null "
                                    + "and is not usable by the space");
        } catch (TransactionException e) {}
View Full Code Here

        AssociationDescriptor ad = AssociationDescriptor.create("Spaced Out", JavaSpace05.class, "AssociationFutureTest");
        DefaultAssociationManagement mgr = new DefaultAssociationManagement();
        Association<JavaSpace05> a = mgr.addAssociationDescriptor(ad);
        Future<JavaSpace05> future = a.getServiceFuture();
        Throwable thrown = null;
        JavaSpace05 space = null;
        try {
            space = future.get();
        } catch (Exception e) {
            thrown = e;
            e.printStackTrace();
View Full Code Here

TOP

Related Classes of net.jini.space.JavaSpace05

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.