Package net.jini.space

Examples of net.jini.space.JavaSpace05


    /** Space under test */
    public void run() throws Exception {
  // Initialize our selves

        specifyServices(new Class[] { JavaSpace.class });
        final JavaSpace05 space = (JavaSpace05)services[0];

  final int threadCount =
      getConfig().getIntConfigVal(configNameBase + "threadCount", 10);
  final int trials =
      getConfig().getIntConfigVal(configNameBase + "trials", 10);
  final int batchSize =
      getConfig().getIntConfigVal(configNameBase + "batchSize", 100);
  final int testSetSize =
      getConfig().getIntConfigVal(configNameBase + "testSetSize", 1500);

  final LeaseRenewalManager lrm = new LeaseRenewalManager();

  logger.log(Level.INFO, "threadCount = " + threadCount);
  logger.log(Level.INFO, "trials = " + trials);
  logger.log(Level.INFO, "batchSize = " + batchSize);
  logger.log(Level.INFO, "testSetSize = " + testSetSize);


  // Initialize the space

  logger.log(Level.INFO, "Writing test entries");

  final List testSet = new java.util.LinkedList();
  for (int i=0; i<testSetSize; i++)
      testSet.add(TestEntries.newEntry());

  final Long maxValue = new Long(Lease.FOREVER);
  for (Iterator i=testSet.iterator(); i.hasNext();) {
      final List entries = new LinkedList();
      final List leases = new ArrayList();
      for (int j=0; j<100 && i.hasNext(); j++) {
    entries.add(i.next());
    leases.add(maxValue);
      }

      space.write(entries, null, leases);
  }

  logger.log(Level.INFO, "Test entries writen");

 
View Full Code Here


    /** Space under test */
    public void run() throws Exception {
  // Initialize our selves

        specifyServices(new Class[] { JavaSpace.class });
        final JavaSpace05 space = (JavaSpace05)services[0];

  final int threadCount =
      getConfig().getIntConfigVal(configNameBase + "threadCount", 5);
  final int trials =
      getConfig().getIntConfigVal(configNameBase + "trials", 10);
  final int batchSize =
      getConfig().getIntConfigVal(configNameBase + "batchSize", 100);
  final int testSetSize =
      getConfig().getIntConfigVal(configNameBase + "testSetSize", 1500);

  final LeaseRenewalManager lrm = new LeaseRenewalManager();

  logger.log(Level.INFO, "threadCount = " + threadCount);
  logger.log(Level.INFO, "trials = " + trials);
  logger.log(Level.INFO, "batchSize = " + batchSize);
  logger.log(Level.INFO, "testSetSize = " + testSetSize);


  // Initialize the space

  logger.log(Level.INFO, "Writing test entries");

  final List testSet = new java.util.LinkedList();
  for (int i=0; i<testSetSize; i++)
      testSet.add(TestEntries.newEntry());

  final Long maxValue = new Long(Lease.FOREVER);
  for (Iterator i=testSet.iterator(); i.hasNext();) {
      final List entries = new LinkedList();
      final List leases = new ArrayList();
      for (int j=0; j<100 && i.hasNext(); j++) {
    entries.add(i.next());
    leases.add(maxValue);
      }

      space.write(entries, null, leases);
  }

  logger.log(Level.INFO, "Test entries writen");

 
View Full Code Here

        /*
         * No more entries can be added to exhausted match set. It also tests
         * that an entry is removed from match set after performing
         * MatchSet.next() method
         */
        JavaSpace05 space05 = (JavaSpace05) space;
        templates.add(sampleEntry1);
        MatchSet matchSet = space05.contents(templates, null, Lease.ANY,
                                             MAX_ENTRIES);
        if (matchSet.next() == null) {
            throw new TestException("Match set is exhausted. "
                                    + "But it shouldn't be.");
        }

        // now it is supposed to be exhausted
        if (matchSet.next() != null) {
            throw new TestException("Match set was not exhausted. "
                                    + "But should have been.");
        }
        space.write(sampleEntry1, null, leaseForeverTime);
        Thread.sleep(1000);
        if (matchSet.next() != null) {
            throw new TestException("An entry added to exhausted match set. "
                                    + "But must not have been.");
        }
        reset();

        /*
         * After maxEntries entries are yielded by next invocations the match
         * set becomes empty. For this test case let maxEntries = 2
         */
        templates.add(null);    // for 3 existing entries
        matchSet = space05.contents(templates, null, Lease.ANY, 2);
        matchSet.next();
        matchSet.next();
        if (matchSet.next() != null) {
            throw new TestException("Match set is not empty after maxEntries "
                                    + "are yielded by next invocations");
        }
        reset();

        /*
         * The initial duration of the lease must be less than or equal to
         * leaseDuration. Let leaseDuration = instantTime.
         */
        templates.add(null);    // for 3 existing entries
        matchSet = space05.contents(templates, null, leaseForeverTime,
                                    MAX_ENTRIES);
        Lease lease = matchSet.getLease();
        if (lease != null) {
            long initialDuration = lease.getExpiration()
                    - System.currentTimeMillis();
            if (initialDuration > leaseForeverTime) {
                throw new TestException("Initial duration of the lease "
                                        + "is more than leaseDuration");
            }
        }  // else Lease is not tested as the matchset is not leased
        reset();

        templates.add((SimpleEntry) sampleEntry1.clone());
        templates.add("not an Entry");
        try {
            space05.contents(templates, null, Lease.ANY, MAX_ENTRIES);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when a non-null element of tepmlates "
                                    + "is not an instance on Entry");
        } catch (IllegalArgumentException e) {}

        templates.clear();
        try {
            space05.contents(templates, null, Lease.ANY, MAX_ENTRIES);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when templates is empty");
        } catch (IllegalArgumentException e) {}

        templates.add((SimpleEntry) sampleEntry1.clone());
        try {
            space05.contents(templates, null, 0, MAX_ENTRIES);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when leaseDuration is nither positive "
                                    + "nor Lease.ANY (0)");
        } catch (IllegalArgumentException e) {}

        try {
            space05.contents(templates, null, Lease.ANY - 1, MAX_ENTRIES);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when leaseDuration is nither positive "
                                    + "nor Lease.ANY (Lease.ANY-1)");
        } catch (IllegalArgumentException e) {}

        try {
            space05.contents(templates, null, Lease.ANY, 0);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when maxEntries is non-positive (0)");
        } catch (IllegalArgumentException e) {}

        try {
            space05.contents(templates, null, Lease.ANY, -1);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when maxEntries is non-positive (-1)");
        } catch (IllegalArgumentException e) {}

        try {
            space05.contents(null, null, Lease.ANY, MAX_ENTRIES);
            throw new TestException("NullPointerException is not thrown "
                                    + "when tmpls is null");
        } catch (NullPointerException e) {}

        cleanSpace(space);
View Full Code Here

                               long maxEntries,
                               List expectedResult,
                               String testName) throws Exception
    {

        JavaSpace05 space05 = (JavaSpace05) space;
        MatchSet matchSet = space05.contents(templates, txn, leaseDuration,
                                             maxEntries);
        ArrayList result = new ArrayList();
        SimpleEntry entry = (SimpleEntry) matchSet.next();
        while (entry != null) {
            result.add(entry);
View Full Code Here

        /*
         * No more entries can be added to exhausted match set. It also tests
         * that an entry is removed from match set after performing
         * MatchSet.next() method
         */
        JavaSpace05 space05 = (JavaSpace05) space;
        templates.add(sampleEntry1);
        txn = getTransaction();
        MatchSet matchSet = space05.contents(templates, txn, Lease.ANY,
                                             MAX_ENTRIES);
        if (matchSet.next() == null) {
            throw new TestException(
                    "Match set is exhausted. But it shouldn't be.");
        }

        // -- now it is supposed to be exhausted
        if (matchSet.next() != null) {
            throw new TestException(
                    "Match set was not exhausted. But should have been.");
        }
        space.write(sampleEntry1, txn, leaseForeverTime);
        Thread.sleep(1000);
        if (matchSet.next() != null) {
            throw new TestException("An entry added to exhausted match set. "
                                    + "But must not have been.");
        }
        txn.commit();
        reset();

        /*
         * After maxEntries entries are yielded by next invocations the match
         * set becomes empty. For this test case let maxEntries = 2
         */
        templates.add(null);    // for 3 existing entries
        txn = getTransaction();
        matchSet = space05.contents(templates, txn, Lease.ANY, 2);
        matchSet.next();
        matchSet.next();
        if (matchSet.next() != null) {
            throw new TestException("Match set is not empty after maxEntries "
                                    + "are yielded by next invocations");
        }
        txn.commit();
        reset();

        /*
         * The initial duration of the lease must be less than or equal to
         * leaseDuration. Let leaseDuration = instantTime.
         */
        templates.add(null);    // for 3 existing entries
        txn = getTransaction();
        matchSet = space05.contents(templates, txn, leaseForeverTime,
                                    MAX_ENTRIES);
        Lease lease = matchSet.getLease();
        if (lease != null) {
            long initialDuration = lease.getExpiration()
                    - System.currentTimeMillis();
            if (initialDuration > leaseForeverTime) {
                throw new TestException("Initial duration of the lease "
                                        + "is more than leaseDuration");
            }
        } // else Lease is not tested as the matchset is not leased
        txn.commit();
        reset();

        //corresponds to item #6 in this method's comments
        txn = getTransaction();
        templates.add((SimpleEntry) sampleEntry1.clone());
        matchSet = space05.contents(templates, txn, leaseForeverTime,
                                    MAX_ENTRIES);
        matchSet.next();
        SimpleEntry entry = (SimpleEntry) space.take(
                (SimpleEntry) sampleEntry1.clone(), null, instantTime);
        if (entry != null) {
            throw new TestException("Locked entry can be taken "
                                    + "from the space.");
        }
        txn.commit();
        reset();

        //corresponds to item #7 in this method's comments
        txn = getTransaction();
        templates.add((SimpleEntry) sampleEntry1.clone());
        templates.add("not an Entry");
        try {
            space05.contents(templates, txn, Lease.ANY, MAX_ENTRIES);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when a non-null element of tepmlates "
                                    + "is not an instance on Entry");
        } catch (IllegalArgumentException e) {}

        templates.clear();
        try {
            space05.contents(templates, txn, Lease.ANY, MAX_ENTRIES);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when templates is empty");
        } catch (IllegalArgumentException e) {}

        templates.add((SimpleEntry) sampleEntry1.clone());
        try {
            space05.contents(templates, txn, 0, MAX_ENTRIES);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when leaseDuration is nither positive "
                                    + "nor Lease.ANY (0)");
        } catch (IllegalArgumentException e) {}

        try {
            space05.contents(templates, txn, Lease.ANY - 1, MAX_ENTRIES);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when leaseDuration is nither positive "
                                    + "nor Lease.ANY (Lease.ANY-1)");
        } catch (IllegalArgumentException e) {}

        try {
            space05.contents(templates, txn, Lease.ANY, 0);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when maxEntries is non-positive (0)");
        } catch (IllegalArgumentException e) {}

        try {
            space05.contents(templates, txn, Lease.ANY, -1);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when maxEntries is non-positive (-1)");
        } catch (IllegalArgumentException e) {}

        try {
            space05.contents(null, txn, Lease.ANY, MAX_ENTRIES);
            throw new TestException("NullPointerException is not thrown "
                                    + "when tmpls is null");
        } catch (NullPointerException e) {}
        txn.commit();

        // transaction txn is not null and is not usable by the space
        try {
            space05.contents(templates, txn, instantTime, MAX_ENTRIES);
            throw new TestException("TransactionException is not thrown "
                                    + "when getting match set from the space "
                                    + "with transaction which is not null "
                                    + "and is not usable by the space");
        } catch (TransactionException e) {}
View Full Code Here

                               String testName) throws Exception
    {
        if (txn == null) {
            throw new TestException("Transaction is null for test " + testName);
        }
        JavaSpace05 space05 = (JavaSpace05) space;
        MatchSet matchSet = space05.contents(templates, txn, leaseDuration,
                                             maxEntries);
        ArrayList result = new ArrayList();
        SimpleEntry entry = (SimpleEntry) matchSet.next();
        while (entry != null) {
            result.add(entry);
View Full Code Here

     */
    public void run() throws Exception {
        ArrayList registrations = new ArrayList();

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

        TestEventListener05 testEventListener0 = new TestEventListener05();
        templates.add((SimpleEntry) sampleEntry1.clone());
        EventRegistration er0 = space05.registerForAvailabilityEvent(templates,
                null, 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, null, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing one entry to trigger an event");
        registrations.add(er0);
        reset();

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

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

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

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

        TestEventListener05 testEventListener5 = new TestEventListener05();
        templates.add(null);
        EventRegistration er5 = space05.registerForAvailabilityEvent(templates,
                null, true, testEventListener5, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        notifications = testEventListener5.getNotifications();
        expectedResult.add(sampleEntry1);
        expectedResult.add(sampleEntry1);
        space.write(sampleEntry1, null, leaseForeverTime);
        space.write(sampleEntry1, null, 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();

        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,
                null, true, testEventListener6, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        notifications = testEventListener6.getNotifications();
        expectedResult.add(sampleEntry2);
        expectedResult.add(sampleEntry3);
        space.write(sampleEntry2, null, leaseForeverTime);
        space.write(sampleEntry3, null, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing 2 entries to trigger 2 events " +
                           "(with multiple matching templates)");
        registrations.add(er6);
        reset();

        /*
         * 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, null, false,
                testEventListener0a, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        notifications = testEventListener0a.getNotifications();
        expectedResult.add(sampleEntry1)// this entry is to trigger the event
        space.write(sampleEntry1, null, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing one entry to trigger an event");
        registrations.add(er0a);
        reset();

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

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

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

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

        TestEventListener05 testEventListener5a = new TestEventListener05();
        templates.add(null);
        EventRegistration er5a = space05.registerForAvailabilityEvent(
                templates, null, false,
                testEventListener5a, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        notifications = testEventListener5a.getNotifications();
        expectedResult.add(sampleEntry1);
        expectedResult.add(sampleEntry1);
        space.write(sampleEntry1, null, leaseForeverTime);
        space.write(sampleEntry1, null, 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();

        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, null, false,
                testEventListener6a, leaseForeverTime,
                new MarshalledObject("notUsedHere"));
        notifications = testEventListener6a.getNotifications();
        expectedResult.add(sampleEntry2);
        expectedResult.add(sampleEntry3);
        space.write(sampleEntry2, null, leaseForeverTime);
        space.write(sampleEntry3, null, leaseForeverTime);
        Thread.sleep(waitingNotificationsToComeTime);
        checkNotifications(notifications, expectedResult,
                           "Writing 2 entries to trigger 2 events " +
                           "(with multiple matching templates)");
        registrations.add(er6a);
        reset();

        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, null, leaseForeverTime);
        SimpleEntry entry = (SimpleEntry) testSpace.readIfExists(sampleEntry1,
                                                                 null,
                                                                 instantTime);
        if (!sampleEntry1.equals(entry)) {
            throw new TestException("EventRegistration.getSource method "
                                    + "does not return a proper "
                                    + "reference to the space");
        }
        reset();

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

        TestEventListener05 testEventListenerExc = new TestEventListener05();
        templates.add((SimpleEntry) sampleEntry1.clone());
        templates.add("not an Entry");
        try {
            space05.registerForAvailabilityEvent(templates, null, 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, null, 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, null, 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, null, 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, null, true,
                    testEventListenerExc, leaseForeverTime,
                    new MarshalledObject("notUsedHere"));
            throw new TestException("NullPointerException is not thrown "
                                    + "when tmpls is null");
        } catch (NullPointerException e) {}

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

        reset();

        txn = getTransaction();
        templates.add((SimpleEntry) sampleEntry1.clone());
        templates.add("Not an antry");
        JavaSpace05 space05 = (JavaSpace05) space;
        try {
            space05.take(templates, txn, instantTime, MAX_ENTRIES);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when templates contain not an instance "
                                    + "of Entry element");
        } catch (IllegalArgumentException e) {}

        templates.clear();
        try {
            space05.take(templates, txn, instantTime, MAX_ENTRIES);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when templates is empty");
        } catch (IllegalArgumentException e) {}

        templates.add((SimpleEntry) sampleEntry1.clone());
        try {
            space05.take(templates, txn, -1, MAX_ENTRIES);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when timout is negative (-1)");
        } catch (IllegalArgumentException e) {}

        try {
            space05.take(templates, txn, instantTime, 0);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when maxEntries is non-positive (0)");
        } catch (IllegalArgumentException e) {}

        try {
            space05.take(templates, txn, instantTime, -1);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when maxEntries is non-positive (-1)");
        } catch (IllegalArgumentException e) {}

        try {
            space05.take(null, txn, instantTime, MAX_ENTRIES);
            throw new TestException("NullPointerException is not thrown "
                                    + "when templates is null");
        } catch (NullPointerException e) {}

        txn.commit();

        // transaction txn is not null and is not usable by the space
        try {
            space05.take(templates, txn, instantTime, MAX_ENTRIES);
            throw new TestException("TransactionException is not thrown "
                                    + "when taking from the space with "
                                    + "transaction which is not null "
                                    + "and is not usable by the space");
        } catch (TransactionException e) {}
View Full Code Here

        reset();

        // corresponds to comments #6 to this method:
        templates.add((SimpleEntry) sampleEntry1.clone());
        templates.add("Not an antry");
        JavaSpace05 space05 = (JavaSpace05) space;
        try {
            space05.take(templates, null, instantTime, MAX_ENTRIES);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when templates contain not an instance "
                                    + "of Entry element");
        } catch (IllegalArgumentException e) {}

        templates.clear();
        try {
            space05.take(templates, null, instantTime, MAX_ENTRIES);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when templates is empty");
        } catch (IllegalArgumentException e) {}

        templates.add((SimpleEntry) sampleEntry1.clone());
        try {
            space05.take(templates, null, -1, MAX_ENTRIES);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when timout is negative (-1)");
        } catch (IllegalArgumentException e) {}

        try {
            space05.take(templates, null, instantTime, 0);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when maxEntries is non-positive (0)");
        } catch (IllegalArgumentException e) {}

        try {
            space05.take(templates, null, instantTime, -1);
            throw new TestException("IllegalArgumentException is not thrown "
                                    + "when maxEntries is non-positive (-1)");
        } catch (IllegalArgumentException e) {}

        try {
            space05.take(null, null, instantTime, MAX_ENTRIES);
            throw new TestException("NullPointerException is not thrown "
                                    + "when templates is null");
        } catch (NullPointerException e) {}

        /*
 
View Full Code Here

                               long timeout,
                               long maxEntries,
                               List expectedResult,
                               String testName) throws Exception
    {
        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

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.