Package com.sun.jini.test.spec.javaspace.conformance

Examples of com.sun.jini.test.spec.javaspace.conformance.SimpleEntry


     *
     * <P>Notes:<BR>For more information see the JavaSpaces specification
     * sections 2.6, 3.1.</P>
     */
    public void run() throws Exception {
        SimpleEntry sampleEntry = new SimpleEntry("TestEntry #1", 1);
        Entry snapshot;
        SimpleEntry result;
        Transaction txn1, txn2;

        // first check that space is empty
        if (!checkSpace(space)) {
            throw new TestException(
View Full Code Here


     *
     * <P>Notes:<BR>For more information see the JavaSpaces specification
     * sections 2.4, 2.6.</P>
     */
    public void run() throws Exception {
        SimpleEntry sampleEntry1 = new SimpleEntry("TestEntry #1", 1);
        SimpleEntry sampleEntry2 = new SimpleEntry("TestEntry #2", 2);
        SimpleEntry sampleEntry3 = new SimpleEntry("TestEntry #1", 2);
        SimpleEntry template;
        Transaction txn;
        String msg;

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

        // write three sample entries twice to the space
        space.write(sampleEntry1, null, leaseForeverTime);
        space.write(sampleEntry1, null, leaseForeverTime);
        space.write(sampleEntry2, null, leaseForeverTime);
        space.write(sampleEntry2, null, leaseForeverTime);
        space.write(sampleEntry3, null, leaseForeverTime);
        space.write(sampleEntry3, null, leaseForeverTime);

        // create the non null transaction
        txn = getTransaction();

        /*
         * readIfExists 1-st entry from the space using snapshot of
         * the same one as a template with JavaSpace.NO_WAIT timeout
         * within the transaction
         */
        msg = testTemplate(sampleEntry1, txn, JavaSpace.NO_WAIT, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        /*
         * readIfExists sample entry from the space using snapshots of
         * wrong template entries and JavaSpace.NO_WAIT timeout
         * within the transaction
         */
        template = new SimpleEntry("TestEntry #3", 1);
        msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // 2-nd wrong template
        template = new SimpleEntry("TestEntry #1", 3);
        msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // 3-rd wrong template
        template = new SimpleEntry("TestEntry #3", 3);
        msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // 4-th wrong template
        template = new SimpleEntry(null, 3);
        msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // 5-th wrong template
        template = new SimpleEntry("TestEntry #3", null);
        msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        /*
         * readIfExists entry from the space using snapshot of null as a
         * template and JavaSpace.NO_WAIT timeout within the transaction
         */
        msg = testTemplate(null, txn, JavaSpace.NO_WAIT, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        /*
         * readIfExists sample entries from the space using snapshots of
         * templates with null as a wildcard for different fields
         * and JavaSpace.NO_WAIT timeout within the transaction
         */
        template = new SimpleEntry("TestEntry #1", null);
        msg = testTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // try 2-nd template
        template = new SimpleEntry(null, 2);
        msg = testTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // 3-rd template
        template = new SimpleEntry(null, null);
        msg = testTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }
View Full Code Here

     *
     * <P>Notes:<BR>For more information see the JavaSpaces specification
     * sections 2.6, 3.1</P>
     */
    public void run() throws Exception {
        SimpleEntry sampleEntry1 = new SimpleEntry("TestEntry #1", 1);
        SimpleEntry sampleEntry2 = new SimpleEntry("TestEntry #2", 2);
        Entry snapshot1;
        Entry snapshot2;
        SimpleEntry result;
        Transaction txn;
        long leaseTime1 = timeout1;
        long leaseTime2 = timeout2;

        // first check that space is empty
View Full Code Here

     *
     * <P>Notes:<BR>For more information see the JavaSpaces specification
     * sections 2.5, 2.6.</P>
     */
    public void run() throws Exception {
        SimpleEntry sampleEntry1 = new SimpleEntry("TestEntry #1", 1);
        SimpleEntry sampleEntry2 = new SimpleEntry("TestEntry #2", 2);
        SimpleEntry sampleEntry3 = new SimpleEntry("TestEntry #1", 2);
        SimpleEntry template;
        Transaction txn;
        String msg;

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

        // create the non null transaction
        txn = getTransaction();

        // write three sample entries into the space
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        /*
         * takeIfExists 1-st entry from the space using snapshot of
         * the same one as a template within the transaction
         */
        msg = testTemplate(sampleEntry1, txn, Long.MAX_VALUE, 0, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // write taken entry back to the space
        space.write(sampleEntry1, txn, leaseForeverTime);

        /*
         * takeIfExists sample entry from the space using snapshots of
         * different wrong template entries within the transaction
         */
        template = new SimpleEntry("TestEntry #3", 1);
        msg = testWrongTemplate(template, txn, checkTime, 0, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // 2-nd wrong template
        template = new SimpleEntry("TestEntry #1", 3);
        msg = testWrongTemplate(template, txn, timeout1, 0, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // 3-rd wrong template
        template = new SimpleEntry("TestEntry #3", 3);
        msg = testWrongTemplate(template, txn, timeout2, 0, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // 4-th wrong template
        template = new SimpleEntry(null, 3);
        msg = testWrongTemplate(template, txn, checkTime, 0, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // 5-th wrong template
        template = new SimpleEntry("TestEntry #3", null);
        msg = testWrongTemplate(template, txn, timeout2, 0, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        /*
         * takeIfExists entry from the space using snapshot of null
         * as a template within the transaction
         */
        msg = testTemplate(null, txn, checkTime, 0, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // clean the space and write 3 entries again
        cleanSpace(space, txn);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        /*
         * takeIfExists sample entries from the space using snapshots of
         * templates with null as a wildcard for different fields
         * within the transaction
         */
        template = new SimpleEntry("TestEntry #1", null);
        msg = testTemplate(template, txn, checkTime, 0, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // clean the space and write 3 entries again
        cleanSpace(space, txn);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        // try 2-nd template
        template = new SimpleEntry(null, 2);
        msg = testTemplate(template, txn, timeout1, 0, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // clean the space and write 3 entries again
        cleanSpace(space, txn);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        // 3-rd template
        template = new SimpleEntry(null, null);
        msg = testTemplate(template, txn, timeout2, 0, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }
View Full Code Here

        boolean[] failMatrix = new boolean[12];
        boolean[] snsh_failMatrix = new boolean[12];
        boolean failed = false;
        long[] evMatrix = new long[] {
            3, 3, 3, 0, 0, 0, 0, 0, 9, 6, 6, 9 };
        SimpleEntry sampleEntry1 = new SimpleEntry("TestEntry #1", 1);
        SimpleEntry sampleEntry2 = new SimpleEntry("TestEntry #2", 2);
        SimpleEntry sampleEntry3 = new SimpleEntry("TestEntry #1", 2);
        Entry snapshot1;
        Entry snapshot2;
        Entry snapshot3;
        SimpleEntry template;
        Transaction txn;
        int i;

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

        // create snapshots of sample entries
        snapshot1 = space.snapshot(sampleEntry1);
        snapshot2 = space.snapshot(sampleEntry2);
        snapshot3 = space.snapshot(sampleEntry3);

        // create the non null transaction
        txn = getTransaction();

        /*
         * init 3 RemoteEvent counters for each of sample entries
         * and their snapshots
         */
        snsh_ncs[0] = new SnapshotNotifyCounter(sampleEntry1, Lease.FOREVER,
                space);
        snsh_ncs[1] = new SnapshotNotifyCounter(sampleEntry2, Lease.FOREVER,
                space);
        snsh_ncs[2] = new SnapshotNotifyCounter(sampleEntry3, Lease.FOREVER,
                space);

        // init 5 counters with wrong templates and their snapshots
        template = new SimpleEntry("TestEntry #3", 1);
        snsh_ncs[3] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

        // 2-nd wrong template and it's snapshot
        template = new SimpleEntry("TestEntry #1", 3);
        snsh_ncs[4] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

        // 3-rd wrong template and it's snapshot
        template = new SimpleEntry("TestEntry #3", 3);
        snsh_ncs[5] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

        // 4-th wrong template and it's snapshot
        template = new SimpleEntry(null, 3);
        snsh_ncs[6] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

        // 5-th wrong template and it's snapshot
        template = new SimpleEntry("TestEntry #3", null);
        snsh_ncs[7] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

        // init counter with null entry as a template and it's snapshot
        snsh_ncs[8] = new SnapshotNotifyCounter(null, Lease.FOREVER, space);

        /*
         * init 3 counters for templates with null values for different
         * fields and their snapshots
         */
        template = new SimpleEntry("TestEntry #1", null);
        snsh_ncs[9] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

        // 2-nd template and it's snapshot
        template = new SimpleEntry(null, 2);
        snsh_ncs[10] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

        // 3-rd template and it's snapshot
        template = new SimpleEntry(null, null);
        snsh_ncs[11] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

        // now register all counters within the transaction
        for (i = 0; i < 12; i++) {
            snsh_ers[i] = space.notify(snsh_ncs[i].getTemplate(), txn,
                    snsh_ncs[i], snsh_ncs[i].getLeaseTime(), null);
        }

        // sleep for a while to let all listeners register properly
        Thread.sleep(timeout1);
        logDebugText("now sleeping for " + timeout1
                + " to let all listeners register properly.");

        /*
         * write 3 sample entries to the space 3 times
         * within the transaction
         */
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        logDebugText("3 sample entries have been written"
                + " to the space 3 times.");

        // wait for a while to let all listeners get notifications
        logDebugText("now sleeping for " + timeout1
                + " to let all listeners get notifications.");
        Thread.sleep(timeout1);

        // check, that listeners got required number of notifications
        for (i = 0; i < 12; i++) {
            if (snsh_ncs[i].getEventsNum(snsh_ers[i]) != evMatrix[i]) {
                failed = true;
                snsh_failMatrix[i] = true;
            } else {
                snsh_failMatrix[i] = false;
            }
        }

        for (i = 0; i < 12; i++) {
            if (snsh_failMatrix[i]) {
                logDebugText("FAILED: " + snsh_ncs[i] + " has got "
                        + snsh_ncs[i].getEventsNum(snsh_ers[i])
                        + " notifications instead of " + evMatrix[i]
                        + " required.");
            } else {
                logDebugText(snsh_ncs[i].toString() + " has got "
                        + snsh_ncs[i].getEventsNum(snsh_ers[i])
                        + " notifications as expected");
            }
        }
        logDebugText("Stage 1 with writing ordinal entries has been"
                + " completed.");
        logDebugText("------------------------------\n");
        logDebugText("Starting 2-nd stage with snapshots.");

        // clean the space
        cleanSpace(space, txn);

        /*
         * init 3 RemoteEvent counters for each of sample entries
         * and their snapshots
         */
        ncs[0] = new NotifyCounter(sampleEntry1, Lease.FOREVER);
        ncs[1] = new NotifyCounter(sampleEntry2, Lease.FOREVER);
        ncs[2] = new NotifyCounter(sampleEntry3, Lease.FOREVER);
        snsh_ncs[0] = new SnapshotNotifyCounter(sampleEntry1, Lease.FOREVER,
                space);
        snsh_ncs[1] = new SnapshotNotifyCounter(sampleEntry2, Lease.FOREVER,
                space);
        snsh_ncs[2] = new SnapshotNotifyCounter(sampleEntry3, Lease.FOREVER,
                space);

        // init 5 counters with wrong templates and their snapshots
        template = new SimpleEntry("TestEntry #3", 1);
        ncs[3] = new NotifyCounter(template, Lease.FOREVER);
        snsh_ncs[3] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

        // 2-nd wrong template and it's snapshot
        template = new SimpleEntry("TestEntry #1", 3);
        ncs[4] = new NotifyCounter(template, Lease.FOREVER);
        snsh_ncs[4] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

        // 3-rd wrong template and it's snapshot
        template = new SimpleEntry("TestEntry #3", 3);
        ncs[5] = new NotifyCounter(template, Lease.FOREVER);
        snsh_ncs[5] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

        // 4-th wrong template and it's snapshot
        template = new SimpleEntry(null, 3);
        ncs[6] = new NotifyCounter(template, Lease.FOREVER);
        snsh_ncs[6] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

        // 5-th wrong template and it's snapshot
        template = new SimpleEntry("TestEntry #3", null);
        ncs[7] = new NotifyCounter(template, Lease.FOREVER);
        snsh_ncs[7] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

        // init counter with null entry as a template and it's snapshot
        ncs[8] = new NotifyCounter(null, Lease.FOREVER);
        snsh_ncs[8] = new SnapshotNotifyCounter(null, Lease.FOREVER, space);

        /*
         * init 3 counters for templates with null values for different
         * fields and their snapshots
         */
        template = new SimpleEntry("TestEntry #1", null);
        ncs[9] = new NotifyCounter(template, Lease.FOREVER);
        snsh_ncs[9] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

        // 2-nd template and it's snapshot
        template = new SimpleEntry(null, 2);
        ncs[10] = new NotifyCounter(template, Lease.FOREVER);
        snsh_ncs[10] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

        // 3-rd template and it's snapshot
        template = new SimpleEntry(null, null);
        ncs[11] = new NotifyCounter(template, Lease.FOREVER);
        snsh_ncs[11] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

        // now register all counters within the transaction
View Full Code Here

     *
     * <P>Notes:<BR>For more information see the JavaSpaces specification
     * sections 2.5, 2.6.</P>
     */
    public void run() throws Exception {
        SimpleEntry sampleEntry1 = new SimpleEntry("TestEntry #1", 1);
        SimpleEntry sampleEntry2 = new SimpleEntry("TestEntry #2", 2);
        SimpleEntry sampleEntry3 = new SimpleEntry("TestEntry #1", 2);
        SimpleEntry template;
        Transaction txn;
        String msg;

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

        // create the non null transaction
        txn = getTransaction();

        // write two sample entries twice to the space
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);

        /*
         * take 1-st entry twice from the space using snapshot of the same
         * one as a template within the transaction
         */
        for (int i = 1; i <= 2; i++) {
            msg = testTemplate(sampleEntry1, txn, Long.MAX_VALUE, i, 2,
                    false);

            if (msg != null) {
                throw new TestException(msg);
            }
        }

        // write taken entries to the space again
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry1, txn, leaseForeverTime);

        // write 3-rd sample entry twice to the space
        space.write(sampleEntry3, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        /*
         * Take entry from the space using snapshot of null as a template
         * within the transaction 6 times to take all written
         * entries from the space.
         */
        for (int i = 1; i <= 6; i++) {
            msg = testTemplate(null, txn, checkTime, i, 6, false);

            if (msg != null) {
                throw new TestException(msg);
            }
        }

        // write all taken entries to the space again
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        /*
         * Take entry from the space using snapshot of template with
         * 1-st null field within the transaction 4 times to take
         * all matching written entries from the space.
         */
        template = new SimpleEntry(null, 2);

        for (int i = 1; i <= 4; i++) {
            msg = testTemplate(template, txn, timeout1, i, 4, false);

            if (msg != null) {
                throw new TestException(msg);
            }
        }

        // write taken entries back to the space
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        /*
         * Take entry from the space using snapshot of template with
         * 2-nd null field within the transaction 4 times to take
         * all matching written entries from the space.
         */
        template = new SimpleEntry("TestEntry #1", null);

        for (int i = 1; i <= 4; i++) {
            msg = testTemplate(template, txn, timeout2, i, 4, false);

            if (msg != null) {
                throw new TestException(msg);
            }
        }

        // write taken entries back to the space
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        /*
         * Take entry from the space using snapshot of template with
         * both null fields within the transaction 6 times to take
         * all matching written entries from the space.
         */
        template = new SimpleEntry(null, null);

        for (int i = 1; i <= 6; i++) {
            msg = testTemplate(template, txn, checkTime, i, 6, false);

            if (msg != null) {
View Full Code Here

     *
     * <P>Notes:<BR>For more information see the JavaSpaces specification
     * sections 2.5, 2.6.</P>
     */
    public void run() throws Exception {
        SimpleEntry sampleEntry1 = new SimpleEntry("TestEntry #1", 1);
        SimpleEntry sampleEntry2 = new SimpleEntry("TestEntry #2", 2);
        SimpleEntry sampleEntry3 = new SimpleEntry("TestEntry #1", 2);
        SimpleEntry template;
        Transaction txn;
        String msg;

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

        // create the non null transaction
        txn = getTransaction();

        // write three sample entries into the space
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        /*
         * takeIfExists 1-st entry from the space using snapshot of
         * the same one as a template with JavaSpace.NO_WAIT timeout
         * within the transaction
         */
        msg = testTemplate(sampleEntry1, txn, JavaSpace.NO_WAIT, 0, 0,
                true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // write taken entry back to the space
        space.write(sampleEntry1, txn, leaseForeverTime);

        /*
         * takeIfExists sample entry from the space using snapshots of
         * wrong template entries and JavaSpace.NO_WAIT timeout
         * within the transaction
         */
        template = new SimpleEntry("TestEntry #3", 1);
        msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, 0,
                true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // 2-nd wrong template
        template = new SimpleEntry("TestEntry #1", 3);
        msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, 0,
                true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // 3-rd wrong template
        template = new SimpleEntry("TestEntry #3", 3);
        msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, 0,
                true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // 4-th wrong template
        template = new SimpleEntry(null, 3);
        msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, 0,
                true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // 5-th wrong template
        template = new SimpleEntry("TestEntry #3", null);
        msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, 0,
                true);

        if (msg != null) {
            throw new TestException(msg);
        }

        /*
         * takeIfExists entry from the space using snapshot of null
         * as a template and JavaSpace.NO_WAIT timeout within
         * the transaction
         */
        msg = testTemplate(null, txn, JavaSpace.NO_WAIT, 0, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // clean the space and write 3 entries again
        cleanSpace(space, txn);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        /*
         * takeIfExists sample entries from the space using snapshots of
         * templates with null as a wildcard for different fields
         * and JavaSpace.NO_WAIT timeout within the transaction
         */
        template = new SimpleEntry("TestEntry #1", null);
        msg = testTemplate(template, txn, JavaSpace.NO_WAIT, 0, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // clean the space and write 3 entries again
        cleanSpace(space, txn);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        // try 2-nd template
        template = new SimpleEntry(null, 2);
        msg = testTemplate(template, txn, JavaSpace.NO_WAIT, 0, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }

        // clean the space and write 3 entries again
        cleanSpace(space, txn);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        // 3-rd template
        template = new SimpleEntry(null, null);
        msg = testTemplate(template, txn, JavaSpace.NO_WAIT, 0, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }
View Full Code Here

        boolean[] failMatrix = new boolean[12];
        boolean[] snsh_failMatrix = new boolean[12];
        boolean failed = false;
        long[] evTxnMatrix = new long[] {
            2, 1, 0, 0, 0, 0, 0, 0, 3, 2, 1, 3 };
        SimpleEntry sampleEntry1 = new SimpleEntry("TestEntry #1", 1);
        SimpleEntry sampleEntry2 = new SimpleEntry("TestEntry #2", 2);
        SimpleEntry sampleEntry3 = new SimpleEntry("TestEntry #1", 2);
        Entry snapshot1;
        Entry snapshot2;
        Entry snapshot3;
        SimpleEntry template;
        Transaction txn;
        long leaseTime1 = timeout2 * 3;
        long leaseTime2 = Lease.FOREVER;
        long leaseTime3 = Lease.ANY;
        int i;

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

        // create the non null transaction
        txn = getTransaction();

        // create snapshots of sample entries
        snapshot1 = space.snapshot(sampleEntry1);
        snapshot2 = space.snapshot(sampleEntry2);
        snapshot3 = space.snapshot(sampleEntry3);

        /*
         * init 3 RemoteEvent counters for each of sample entries
         * and their snapshots
         */
        ncs[0] = new NotifyCounter(sampleEntry1, leaseTime1);
        ncs[1] = new NotifyCounter(sampleEntry2, leaseTime2);
        ncs[2] = new NotifyCounter(sampleEntry3, leaseTime3);
        snsh_ncs[0] = new SnapshotNotifyCounter(sampleEntry1, leaseTime1,
                space);
        snsh_ncs[1] = new SnapshotNotifyCounter(sampleEntry2, leaseTime2,
                space);
        snsh_ncs[2] = new SnapshotNotifyCounter(sampleEntry3, leaseTime3,
                space);

        // init 5 counters with wrong templates and their snapshots
        template = new SimpleEntry("TestEntry #3", 1);
        ncs[3] = new NotifyCounter(template, leaseTime1);
        snsh_ncs[3] = new SnapshotNotifyCounter(template, leaseTime1,
                space);

        // 2-nd wrong template and it's snapshot
        template = new SimpleEntry("TestEntry #1", 3);
        ncs[4] = new NotifyCounter(template, leaseTime2);
        snsh_ncs[4] = new SnapshotNotifyCounter(template, leaseTime2,
                space);

        // 3-rd wrong template it's snapshot
        template = new SimpleEntry("TestEntry #3", 3);
        ncs[5] = new NotifyCounter(template, leaseTime3);
        snsh_ncs[5] = new SnapshotNotifyCounter(template, leaseTime3,
                space);

        // 4-th wrong template it's snapshot
        template = new SimpleEntry(null, 3);
        ncs[6] = new NotifyCounter(template, leaseForeverTime);
        snsh_ncs[6] = new SnapshotNotifyCounter(template, leaseForeverTime,
                space);

        // 5-th wrong template it's snapshot
        template = new SimpleEntry("TestEntry #3", null);
        ncs[7] = new NotifyCounter(template, leaseTime1);
        snsh_ncs[7] = new SnapshotNotifyCounter(template, leaseTime1,
                space);

        // init counter with null entry as a template and it's snapshot
        ncs[8] = new NotifyCounter(null, leaseForeverTime);
        snsh_ncs[8] = new SnapshotNotifyCounter(null, leaseForeverTime,
                space);

        // init 3 counters with null values for different fields
        template = new SimpleEntry("TestEntry #1", null);
        ncs[9] = new NotifyCounter(template, leaseTime1);
        snsh_ncs[9] = new SnapshotNotifyCounter(template, leaseTime1,
                space);

        // 2-nd template
        template = new SimpleEntry(null, 2);
        ncs[10] = new NotifyCounter(template, leaseTime2);
        snsh_ncs[10] = new SnapshotNotifyCounter(template, leaseTime2,
                space);

        // 3-rd template
        template = new SimpleEntry(null, null);
        ncs[11] = new NotifyCounter(template, leaseTime3);
        snsh_ncs[11] = new SnapshotNotifyCounter(template, leaseTime3,
                space);

        // now register all counters with null transaction parameter
View Full Code Here

        boolean[] failMatrix = new boolean[12];
        boolean[] snsh_failMatrix = new boolean[12];
        boolean failed = false;
        long[] evMatrix = new long[] {
            3, 3, 3, 0, 0, 0, 0, 0, 9, 6, 6, 9 };
        SimpleEntry sampleEntry1 = new SimpleEntry("TestEntry #1", 1);
        SimpleEntry sampleEntry2 = new SimpleEntry("TestEntry #2", 2);
        SimpleEntry sampleEntry3 = new SimpleEntry("TestEntry #1", 2);
        Entry snapshot1;
        Entry snapshot2;
        Entry snapshot3;
        SimpleEntry template;
        Transaction txn;
        int i;

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

        // create the non null transaction
        txn = getTransaction();

        // create snapshots of sample entries
        snapshot1 = space.snapshot(sampleEntry1);
        snapshot2 = space.snapshot(sampleEntry2);
        snapshot3 = space.snapshot(sampleEntry3);

        /*
         * init 3 RemoteEvent counters for each of sample entries
         * and their snapshots
         */
        snsh_ncs[0] = new SnapshotNotifyCounter(sampleEntry1, Lease.ANY,
                space);
        snsh_ncs[1] = new SnapshotNotifyCounter(sampleEntry2, Lease.ANY,
                space);
        snsh_ncs[2] = new SnapshotNotifyCounter(sampleEntry3, Lease.ANY,
                space);

        // init 5 counters with wrong templates and their snapshots
        template = new SimpleEntry("TestEntry #3", 1);
        snsh_ncs[3] = new SnapshotNotifyCounter(template, Lease.ANY, space);

        // 2-nd wrong template and it's snapshot
        template = new SimpleEntry("TestEntry #1", 3);
        snsh_ncs[4] = new SnapshotNotifyCounter(template, Lease.ANY, space);

        // 3-rd wrong template and it's snapshot
        template = new SimpleEntry("TestEntry #3", 3);
        snsh_ncs[5] = new SnapshotNotifyCounter(template, Lease.ANY, space);

        // 4-th wrong template and it's snapshot
        template = new SimpleEntry(null, 3);
        snsh_ncs[6] = new SnapshotNotifyCounter(template, Lease.ANY, space);

        // 5-th wrong template and it's snapshot
        template = new SimpleEntry("TestEntry #3", null);
        snsh_ncs[7] = new SnapshotNotifyCounter(template, Lease.ANY, space);

        // init counter with null entry as a template and it's snapshot
        snsh_ncs[8] = new SnapshotNotifyCounter(null, Lease.ANY, space);

        /*
         * init 3 counters for templates with null values for different
         * fields and their snapshots
         */
        template = new SimpleEntry("TestEntry #1", null);
        snsh_ncs[9] = new SnapshotNotifyCounter(template, Lease.ANY, space);

        // 2-nd template and it's snapshot
        template = new SimpleEntry(null, 2);
        snsh_ncs[10] = new SnapshotNotifyCounter(template, Lease.ANY,
                space);

        // 3-rd template and it's snapshot
        template = new SimpleEntry(null, null);
        snsh_ncs[11] = new SnapshotNotifyCounter(template, Lease.ANY,
                space);

        // now register all counters
        for (i = 0; i < 12; i++) {
            snsh_ers[i] = space.notify(snsh_ncs[i].getSnapshot(), txn,
                    snsh_ncs[i], snsh_ncs[i].getLeaseTime(), null);
        }

        // sleep for a while to let all listeners register properly
        Thread.sleep(timeout1);
        logDebugText("now sleeping for " + timeout1
                + " to let all listeners register properly.");

        /*
         * write 3 sample entries to the space 3 times
         * within the transaction
         */
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        logDebugText("3 sample entries have been written"
                + " to the space 3 times.");

        // wait for a while to let all listeners get notifications
        logDebugText("now sleeping for " + timeout1
                + " to let all listeners get notifications.");
        Thread.sleep(timeout1);

        // check, that listeners got required number of notifications
        for (i = 0; i < 12; i++) {
            if (snsh_ncs[i].getEventsNum(snsh_ers[i]) != evMatrix[i]) {
                failed = true;
                snsh_failMatrix[i] = true;
            } else {
                snsh_failMatrix[i] = false;
            }
        }

        for (i = 0; i < 12; i++) {
            if (snsh_failMatrix[i]) {
                logDebugText("FAILED: " + snsh_ncs[i] + " has got "
                        + snsh_ncs[i].getEventsNum(snsh_ers[i])
                        + " notifications instead of " + evMatrix[i]
                        + " required.");
            } else {
                logDebugText(snsh_ncs[i].toString() + " has got "
                        + snsh_ncs[i].getEventsNum(snsh_ers[i])
                        + " notifications as expected");
            }
        }
        logDebugText("Stage 1 with writing ordinal entries has been"
                + " completed.");
        logDebugText("------------------------------\n");
        logDebugText("Starting 2-nd stage with snapshots.");

        // clean the space
        cleanSpace(space, txn);

        /*
         * init 3 RemoteEvent counters for each of sample entries
         * and their snapshots
         */
        ncs[0] = new NotifyCounter(sampleEntry1, Lease.ANY);
        ncs[1] = new NotifyCounter(sampleEntry2, Lease.ANY);
        ncs[2] = new NotifyCounter(sampleEntry3, Lease.ANY);
        snsh_ncs[0] = new SnapshotNotifyCounter(sampleEntry1, Lease.ANY,
                space);
        snsh_ncs[1] = new SnapshotNotifyCounter(sampleEntry2, Lease.ANY,
                space);
        snsh_ncs[2] = new SnapshotNotifyCounter(sampleEntry3, Lease.ANY,
                space);

        // init 5 counters with wrong templates and their snapshots
        template = new SimpleEntry("TestEntry #3", 1);
        ncs[3] = new NotifyCounter(template, Lease.ANY);
        snsh_ncs[3] = new SnapshotNotifyCounter(template, Lease.ANY, space);

        // 2-nd wrong template and it's snapshot
        template = new SimpleEntry("TestEntry #1", 3);
        ncs[4] = new NotifyCounter(template, Lease.ANY);
        snsh_ncs[4] = new SnapshotNotifyCounter(template, Lease.ANY, space);

        // 3-rd wrong template and it's snapshot
        template = new SimpleEntry("TestEntry #3", 3);
        ncs[5] = new NotifyCounter(template, Lease.ANY);
        snsh_ncs[5] = new SnapshotNotifyCounter(template, Lease.ANY, space);

        // 4-th wrong template and it's snapshot
        template = new SimpleEntry(null, 3);
        ncs[6] = new NotifyCounter(template, Lease.ANY);
        snsh_ncs[6] = new SnapshotNotifyCounter(template, Lease.ANY, space);

        // 5-th wrong template and it's snapshot
        template = new SimpleEntry("TestEntry #3", null);
        ncs[7] = new NotifyCounter(template, Lease.ANY);
        snsh_ncs[7] = new SnapshotNotifyCounter(template, Lease.ANY, space);

        // init counter with null entry as a template and it's snapshot
        ncs[8] = new NotifyCounter(null, Lease.ANY);
        snsh_ncs[8] = new SnapshotNotifyCounter(null, Lease.ANY, space);

        /*
         * init 3 counters for templates with null values for different
         * fields and their snapshots
         */
        template = new SimpleEntry("TestEntry #1", null);
        ncs[9] = new NotifyCounter(template, Lease.ANY);
        snsh_ncs[9] = new SnapshotNotifyCounter(template, Lease.ANY, space);

        // 2-nd template and it's snapshot
        template = new SimpleEntry(null, 2);
        ncs[10] = new NotifyCounter(template, Lease.ANY);
        snsh_ncs[10] = new SnapshotNotifyCounter(template, Lease.ANY,
                space);

        // 3-rd template and it's snapshot
        template = new SimpleEntry(null, null);
        ncs[11] = new NotifyCounter(template, Lease.ANY);
        snsh_ncs[11] = new SnapshotNotifyCounter(template, Lease.ANY,
                space);

        // now register all counters
View Full Code Here

        boolean[] failMatrix = new boolean[10];
        boolean[] snsh_failMatrix = new boolean[10];
        boolean failed = false;
        long[] evTxnMatrix = new long[] {
            2, 6, 8, 10, 10, 2, 4, 4, 4, 4 };
        SimpleEntry sampleEntry = new SimpleEntry("TestEntry #1", 1);
        Entry snapshot;
        Transaction txn;
        long leaseTime1 = timeout2;
        long leaseTime2 = timeout2 * 2;
        long leaseTime3 = timeout2 * 3;
 
View Full Code Here

TOP

Related Classes of com.sun.jini.test.spec.javaspace.conformance.SimpleEntry

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.