public void testUnlimitedRecords()
        {
            fixture_ = new ValidationPolicyCommandInterestFixture(
                new ValidationPolicyCommandInterest.Options(15 * 1000.0d, -1));

            ArrayList <PibIdentity> identities = new ArrayList <PibIdentity>();

            for (int i = 0; i < 20; ++i)
            {
                PibIdentity identity = fixture_.addSubCertificate(new Name(
                                                                      "/Security/V2/ValidatorFixture/Sub" + i),
                                                                  fixture_.identity_);
                fixture_.cache_.insert(identity.getDefaultKey()
                                       .getDefaultCertificate());
                ILOG.J2CsMapping.Collections.Collections.Add(identities, identity);
            }

            // Signed at 0 seconds.
            Interest interest1 = fixture_.makeCommandInterest(identities[0]);

            fixture_.setNowOffsetMilliseconds(1 * 1000.0d);
            for (int i_0 = 0; i_0 < 20; ++i_0)
            {
                // Signed at +1 seconds.
                Interest interest2 = fixture_
                                     .makeCommandInterest(identities[i_0]);

                validateExpectSuccess(interest2, "Should succeed");
            }

            validateExpectFailure(interest1, "Should fail (timestamp reorder)");
        }
        public void testLimitedRecordLifetime()
        {
            fixture_ = new ValidationPolicyCommandInterestFixture(
                new ValidationPolicyCommandInterest.Options(400 * 1000.0d, 1000,
                                                            300 * 1000.0d));

            // Signed at 0 seconds.
            Interest interest1 = fixture_.makeCommandInterest(fixture_.identity_);

            // Signed at +240 seconds.
            fixture_.setNowOffsetMilliseconds(240 * 1000.0d);
            Interest interest2 = fixture_.makeCommandInterest(fixture_.identity_);

            // Signed at +360 seconds.
            fixture_.setNowOffsetMilliseconds(360 * 1000.0d);
            Interest interest3 = fixture_.makeCommandInterest(fixture_.identity_);

            // Validate at 0 seconds.
            fixture_.setNowOffsetMilliseconds(0.0d);
            validateExpectSuccess(interest1, "Should succeed");

            validateExpectSuccess(interest3, "Should succeed");

            // Validate at +301 seconds.
            fixture_.setNowOffsetMilliseconds(301 * 1000.0d);
            validateExpectSuccess(
                interest2,
                "Should succeed despite the timestamp being reordered, because the record has expired");
        }
        public void testTimestampOutOfGraceNegative()
        {
            fixture_ = new ValidationPolicyCommandInterestFixture(
                new ValidationPolicyCommandInterest.Options(15 * 1000.0d));

            // Signed at 0 seconds.
            Interest interest1 = fixture_.makeCommandInterest(fixture_.identity_);

            // Signed at +1 seconds.
            fixture_.setNowOffsetMilliseconds(1 * 1000.0d);
            Interest interest2 = fixture_.makeCommandInterest(fixture_.identity_);

            // Signed at +2 seconds.
            fixture_.setNowOffsetMilliseconds(2 * 1000.0d);
            Interest interest3 = fixture_.makeCommandInterest(fixture_.identity_);

            // Verifying at -16 seconds.
            fixture_.setNowOffsetMilliseconds(-16 * 1000.0d);
            validateExpectFailure(interest1,
                                  "Should fail (timestamp outside the grace period)");

            // The CommandInterestValidator should not remember interest1's timestamp.
            validateExpectFailure(interest2,
                                  "Should fail (timestamp outside the grace period)");

            // The CommandInterestValidator should not remember interest2's timestamp, and
            // should treat interest3 as initial.
            // Verifying at +2 seconds.
            fixture_.setNowOffsetMilliseconds(2 * 1000.0d);
            validateExpectSuccess(interest3, "Should succeed");
        }
        public void setUp()
        {
            // Turn off INFO log messages.
            ILOG.J2CsMapping.Util.Logging.Logger.getLogger("").setLevel(ILOG.J2CsMapping.Util.Logging.Level.SEVERE);

            fixture_ = new ValidationPolicyCommandInterestFixture();
        }
        public void testLimitedRecords()
        {
            fixture_ = new ValidationPolicyCommandInterestFixture(
                new ValidationPolicyCommandInterest.Options(15 * 1000.0d, 3));

            PibIdentity identity1 = fixture_.addSubCertificate(new Name(
                                                                   "/Security/V2/ValidatorFixture/Sub1"), fixture_.identity_);

            fixture_.cache_.insert(identity1.getDefaultKey()
                                   .getDefaultCertificate());
            PibIdentity identity2 = fixture_.addSubCertificate(new Name(
                                                                   "/Security/V2/ValidatorFixture/Sub2"), fixture_.identity_);

            fixture_.cache_.insert(identity2.getDefaultKey()
                                   .getDefaultCertificate());
            PibIdentity identity3 = fixture_.addSubCertificate(new Name(
                                                                   "/Security/V2/ValidatorFixture/Sub3"), fixture_.identity_);

            fixture_.cache_.insert(identity3.getDefaultKey()
                                   .getDefaultCertificate());
            PibIdentity identity4 = fixture_.addSubCertificate(new Name(
                                                                   "/Security/V2/ValidatorFixture/Sub4"), fixture_.identity_);

            fixture_.cache_.insert(identity4.getDefaultKey()
                                   .getDefaultCertificate());

            Interest interest1 = fixture_.makeCommandInterest(identity2);
            Interest interest2 = fixture_.makeCommandInterest(identity3);
            Interest interest3 = fixture_.makeCommandInterest(identity4);
            // Signed at 0 seconds.
            Interest interest00 = fixture_.makeCommandInterest(identity1);

            // Signed at +1 seconds.
            fixture_.setNowOffsetMilliseconds(1 * 1000.0d);
            Interest interest01 = fixture_.makeCommandInterest(identity1);

            // Signed at +2 seconds.
            fixture_.setNowOffsetMilliseconds(2 * 1000.0d);
            Interest interest02 = fixture_.makeCommandInterest(identity1);

            validateExpectSuccess(interest00, "Should succeed");

            validateExpectSuccess(interest02, "Should succeed");

            validateExpectSuccess(interest1, "Should succeed");

            validateExpectSuccess(interest2, "Should succeed");

            validateExpectSuccess(interest3, "Should succeed, forgets identity1");

            validateExpectSuccess(
                interest01,
                "Should succeed despite timestamp is reordered, because the record has been evicted");
        }
        public void testZeroRecords()
        {
            fixture_ = new ValidationPolicyCommandInterestFixture(
                new ValidationPolicyCommandInterest.Options(15 * 1000.0d, 0));

            // Signed at 0 seconds.
            Interest interest1 = fixture_.makeCommandInterest(fixture_.identity_);

            // Signed at +1 seconds.
            fixture_.setNowOffsetMilliseconds(1 * 1000.0d);
            Interest interest2 = fixture_.makeCommandInterest(fixture_.identity_);

            validateExpectSuccess(interest2, "Should succeed");

            validateExpectSuccess(
                interest1,
                "Should succeed despite the timestamp being reordered, because the record isn't kept");
        }
        public void testTimestampOutOfGracePositive()
        {
            fixture_ = new ValidationPolicyCommandInterestFixture(
                new ValidationPolicyCommandInterest.Options(15 * 1000.0d));

            // Signed at 0 seconds.
            Interest interest1 = fixture_.makeCommandInterest(fixture_.identity_);

            // Verifying at +16 seconds.
            fixture_.setNowOffsetMilliseconds(16 * 1000.0d);
            validateExpectFailure(interest1,
                                  "Should fail (timestamp outside the grace period)");

            // Signed at +16 seconds.
            Interest interest2 = fixture_.makeCommandInterest(fixture_.identity_);

            validateExpectSuccess(interest2, "Should succeed");
        }