コード例 #1
0
        public void testMaxNdnPacketSize()
        {
            // Construct an interest whose encoding is one byte larger than getMaxNdnPacketSize.
            int targetSize = net.named_data.jndn.Face.getMaxNdnPacketSize() + 1;
            // Start with an interest which is almost the right size.
            Interest interest = new Interest();
            interest.getName().append(new byte[targetSize]);
            int initialSize = interest.wireEncode().size();
            // Now replace the component with the desired size which trims off the extra encoding.
            interest.setName(new Name().append(new byte[targetSize
                    - (initialSize - targetSize)]));
            int interestSize = interest.wireEncode().size();
            AssertEquals("Wrong interest size for MaxNdnPacketSize", targetSize,
                    interestSize);

            CallbackCounter counter = new CallbackCounter();
            bool gotError = true;
            try {
                face.expressInterest(interest, counter, counter);
                gotError = false;
            } catch (Exception ex) {
            }
            if (!gotError)
                Fail("expressInterest didn't throw an exception when the interest size exceeds getMaxNdnPacketSize()");
        }
コード例 #2
0
        // Returns a CallbackCounter object so we can test data callback, nack callback
        // and timeout behavior.
        private static CallbackCounter runExpressNameTest(Face face,
				String interestName, double timeout, bool useOnNack)
        {
            Name name = new Name(interestName);
            CallbackCounter counter = new CallbackCounter();
            try {
                if (useOnNack)
                    // Debug: Use one of the simpler forms
                    face.expressInterest(new Interest(name), counter, counter,
                            counter, net.named_data.jndn.encoding.WireFormat.getDefaultWireFormat());
                else
                    face.expressInterest(name, counter, counter);
            } catch (IOException ex) {
                ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(TestFaceInterestMethods).FullName).log(
                        ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex);
                return null;
            }

            double startTime = getNowMilliseconds();
            while (getNowMilliseconds() - startTime < timeout
                    && counter.onDataCallCount_ == 0
                    && counter.onTimeoutCallCount_ == 0
                    && counter.onNetworkNackCallCount_ == 0) {
                try {
                    try {
                        face.processEvents();
                    } catch (IOException ex_0) {
                        ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(TestFaceInterestMethods).FullName)
                                .log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex_0);
                        break;
                    } catch (EncodingException ex_1) {
                        ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(TestFaceInterestMethods).FullName)
                                .log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex_1);
                        break;
                    }

                    // We need to sleep for a few milliseconds so we don't use 100% of the CPU.
                    ILOG.J2CsMapping.Threading.ThreadWrapper.sleep(10);
                } catch (ThreadInterruptedException ex_2) {
                    ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(TestFaceInterestMethods).FullName).log(
                            ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex_2);
                    break;
                }
            }

            return counter;
        }
コード例 #3
0
        public void testRemovePending()
        {
            Name name = new Name("/ndn/edu/ucla/remap/");
            CallbackCounter counter = new CallbackCounter();
            long interestID;
            try {
                interestID = face.expressInterest(name, counter, counter);
            } catch (IOException ex) {
                Fail("Error in expressInterest: " + ex);
                return;
            }

            face.removePendingInterest(interestID);

            double timeout = 10000;
            double startTime = getNowMilliseconds();
            while (getNowMilliseconds() - startTime < timeout
                    && counter.onDataCallCount_ == 0
                    && counter.onTimeoutCallCount_ == 0) {
                try {
                    face.processEvents();
                } catch (IOException ex_0) {
                    Fail("Error in processEvents: " + ex_0);
                    return;
                } catch (EncodingException ex_1) {
                    Fail("Error in processEvents: " + ex_1);
                    return;
                }

                try {
                    // We need to sleep for a few milliseconds so we don't use 100% of the CPU.
                    ILOG.J2CsMapping.Threading.ThreadWrapper.sleep(10);
                } catch (ThreadInterruptedException ex_2) {
                    Fail("Error in sleep: " + ex_2);
                    return;
                }
            }

            AssertEquals(
                    "Should not have called data callback after interest was removed",
                    0, counter.onDataCallCount_);
            AssertTrue(
                    "Should not have called timeout callback after interest was removed",
                    counter.onTimeoutCallCount_ == 0);
        }