亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? testfastcronparser.java

?? oscache-2.4.1-full
?? JAVA
字號:
/*
 * Copyright (c) 2002-2003 by OpenSymphony
 * All rights reserved.
 */
package com.opensymphony.oscache.util;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.*;

/**
 *
 * @author <a href="&#109;a&#105;&#108;&#116;&#111;:chris&#64;swebtec.&#99;&#111;&#109;">Chris Miller</a>
 * @author $Author: larst $
 * @version $Revision: 385 $
 */
public class TestFastCronParser extends TestCase {
    public TestFastCronParser(String str) {
        super(str);
    }

    /**
    * This methods returns the name of this test class to JUnit
    * <p>
    * @return The name of this class
    */
    public static Test suite() {
        return new TestSuite(TestFastCronParser.class);
    }

    /**
    * Tests to see if the cron class can calculate the previous matching
    * time correctly in various circumstances
    */
    public void testEvaluations() {
        // Minute tests
        cronCall("01/01/2003 0:00", "45 * * * *", "31/12/2002 23:45", false);
        cronCall("01/01/2003 0:00", "45-47,48,49 * * * *", "31/12/2002 23:49", false);
        cronCall("01/01/2003 0:00", "2/5 * * * *", "31/12/2002 23:57", false);

        // Hour tests
        cronCall("20/12/2003 10:00", "* 3/4 * * *", "20/12/2003 07:59", false);
        cronCall("20/12/2003 0:00", "* 3 * * *", "19/12/2003 03:59", false);

        // Day of month tests
        cronCall("07/01/2003 0:00", "30 * 1 * *", "01/01/2003 23:30", false);
        cronCall("01/01/2003 0:00", "10 * 22 * *", "22/12/2002 23:10", false);
        cronCall("01/01/2003 0:00", "30 23 19 * *", "19/12/2002 23:30", false);
        cronCall("01/01/2003 0:00", "30 23 21 * *", "21/12/2002 23:30", false);
        cronCall("01/01/2003 0:01", "* * 21 * *", "21/12/2002 23:59", false);
        cronCall("10/07/2003 0:00", "* * 30,31 * *", "30/06/2003 23:59", false);

        // Test month rollovers for months with 28,29,30 and 31 days
        cronCall("01/03/2002 0:11", "* * * 2 *", "28/02/2002 23:59", false);
        cronCall("01/03/2004 0:44", "* * * 2 *", "29/02/2004 23:59", false);
        cronCall("01/04/2002 0:00", "* * * 3 *", "31/03/2002 23:59", false);
        cronCall("01/05/2002 0:00", "* * * 4 *", "30/04/2002 23:59", false);

        // Other month tests (including year rollover)
        cronCall("01/01/2003 5:00", "10 * * 6 *", "30/06/2002 23:10", false);
        cronCall("01/01/2003 5:00", "10 * * February,April-Jun *", "30/06/2002 23:10", false);
        cronCall("01/01/2003 0:00", "0 12 1 6 *", "01/06/2002 12:00", false);
        cronCall("11/09/1988 14:23", "* 12 1 6 *", "01/06/1988 12:59", false);
        cronCall("11/03/1988 14:23", "* 12 1 6 *", "01/06/1987 12:59", false);
        cronCall("11/03/1988 14:23", "* 2,4-8,15 * 6 *", "30/06/1987 15:59", false);
        cronCall("11/03/1988 14:23", "20 * * january,FeB,Mar,april,May,JuNE,July,Augu,SEPT-October,Nov,DECEM *", "11/03/1988 14:20", false);

        // Day of week tests
        cronCall("26/06/2003 10:00", "30 6 * * 0", "22/06/2003 06:30", false);
        cronCall("26/06/2003 10:00", "30 6 * * sunday", "22/06/2003 06:30", false);
        cronCall("26/06/2003 10:00", "30 6 * * SUNDAY", "22/06/2003 06:30", false);
        cronCall("23/06/2003 0:00", "1 12 * * 2", "17/06/2003 12:01", false);
        cronCall("23/06/2003 0:00", "* * * * 3,0,4", "22/06/2003 23:59", false);
        cronCall("23/06/2003 0:00", "* * * * 5", "20/06/2003 23:59", false);
        cronCall("02/06/2003 18:30", "0 12 * * 2", "27/05/2003 12:00", false);
        cronCall("02/06/2003 18:30", "0 12 * * Tue,Thurs-Sat,2", "31/05/2003 12:00", false);
        cronCall("02/06/2003 18:30", "0 12 * * Mon-tuesday,wed,THURS-FRiday,Sat-SUNDAY", "02/06/2003 12:00", false);

        // Leap year tests
        cronCall("01/03/2003 12:00", "1 12 * * *", "28/02/2003 12:01", false); // non-leap year
        cronCall("01/03/2004 12:00", "1 12 * * *", "29/02/2004 12:01", false); // leap year
        cronCall("01/03/2003 12:00", "1 23 * * 0", "23/02/2003 23:01", false); // non-leap year
        cronCall("01/03/2004 12:00", "1 23 * * 0", "29/02/2004 23:01", false); // leap year
        cronCall("01/03/2003 12:00", "* * 29 2 *", "29/02/2000 23:59", false); // Find the previous leap-day
        cronCall("01/02/2003 12:00", "* * 29 2 *", "29/02/2000 23:59", false); // Find the previous leap-day
        cronCall("01/02/2004 12:00", "* * 29 2 *", "29/02/2000 23:59", false); // Find the previous leap-day

        // Interval and range tests
        cronCall("20/12/2003 10:00", "* */4 * * *", "20/12/2003 08:59", false);
        cronCall("20/12/2003 10:00", "* 3/2 * * *", "20/12/2003 09:59", false);
        cronCall("20/12/2003 10:00", "1-30/5 10-20/3 * jan-aug/2 *", "31/07/2003 19:26", false);
        cronCall("20/12/2003 10:00", "20-25,27-30/2 10/8 * * *", "19/12/2003 18:29", false);
    }

    /**
    * Tests a range of invalid cron expressions
    */
    public void testInvalidExpressionParsing() {
        FastCronParser parser = new FastCronParser();

        try {
            parser.setCronExpression(null);
            fail("An IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException e) {
            // Expected
        } catch (ParseException e) {
            fail("Expected an IllegalArgumentException but received a ParseException instead");
        }

        /**
        * Not enough tokens
        */
        cronCall("01/01/2003 0:00", "", "", true);
        cronCall("01/01/2003 0:00", "8 * 8/1 *", "", true);

        /**
        * Invalid syntax
        */
        cronCall("01/01/2003 0:00", "* invalid * * *", "", true);
        cronCall("01/01/2003 0:00", "* -1 * * *", "", true);
        cronCall("01/01/2003 0:00", "* * 20 * 0", "", true);
        cronCall("01/01/2003 0:00", "* * 5-6-7 * *", "", true);
        cronCall("01/01/2003 0:00", "* * 5/6-7 * *", "", true);
        cronCall("01/01/2003 0:00", "* * 5-* * *", "", true);
        cronCall("01/01/2003 0:00", "* * 5-6* * *", "", true);
        cronCall("01/01/2003 0:00", "* * * * Mo", "", true);
        cronCall("01/01/2003 0:00", "* * * jxxx *", "", true);
        cronCall("01/01/2003 0:00", "* * * juxx *", "", true);
        cronCall("01/01/2003 0:00", "* * * fbr *", "", true);
        cronCall("01/01/2003 0:00", "* * * mch *", "", true);
        cronCall("01/01/2003 0:00", "* * * mAh *", "", true);
        cronCall("01/01/2003 0:00", "* * * arl *", "", true);
        cronCall("01/01/2003 0:00", "* * * Spteber *", "", true);
        cronCall("01/01/2003 0:00", "* * * otber *", "", true);
        cronCall("01/01/2003 0:00", "* * * nvemtber *", "", true);
        cronCall("01/01/2003 0:00", "* * * Dcmber *", "", true);
        cronCall("01/01/2003 0:00", "* * * * mnday", "", true);
        cronCall("01/01/2003 0:00", "* * * * tsdeday", "", true);
        cronCall("01/01/2003 0:00", "* * * * wdnesday", "", true);
        cronCall("01/01/2003 0:00", "* * * * frday", "", true);
        cronCall("01/01/2003 0:00", "* * * * sdhdatr", "", true);

        /**
        * Values out of range
        */
        cronCall("01/01/2003 0:00", "* * 0 * *", "", true);
        cronCall("01/01/2003 0:00", "* 50 * * *", "", true);
        cronCall("01/01/2003 0:00", "* * * 1-20 *", "", true);
        cronCall("01/01/2003 0:00", "* * 0-20 * *", "", true);
        cronCall("01/01/2003 0:00", "* * 1-40 * *", "", true);
        cronCall("01/01/2003 0:00", "* * * 1 8", "", true);
        cronCall("01/01/2003 0:00", "* * 0/3 * *", "", true);
        cronCall("01/01/2003 0:00", "* * 30 2 *", "", true); // 30th Feb doesn't ever exist!
        cronCall("01/01/2003 0:00", "* * 31 4 *", "", true); // 31st April doesn't ever exist!
    }

    /**
    * This tests the performance of the cron parsing engine. Note that it may take
    * a couple of minutes o run - by default this test is disabled. Comment out the
    * <code>return</code> statement at the start of this method to enable the
    * benchmarking.
    */
    public void testPerformance() {
        if (true) {
            //            return; // Comment out this line to benchmark
        }

        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
        Date date = null;

        try {
            date = sdf.parse("21/01/2003 16:27");
        } catch (ParseException e) {
            fail("Failed to parse date. Please check your unit test code!");
        }

        Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        calendar.setTime(date);

        long baseTime = calendar.getTimeInMillis();

        long time = 0;

        try {
            // Give HotSpot a chance to warm up
            iterate("28 17 22 02 *", baseTime, time, 10000, true);

            // Number of iterations to test
            int count = 1000000;

            // Test the best-case scenario
            long bestCaseTime = iterate("* * * * *", baseTime, time, count, true);
            System.out.println("Best case with parsing took " + bestCaseTime + "ms for " + count + " iterations. (" + (bestCaseTime / (float) count) + "ms per call)");

            // Test a near worst-case scenario
            long worstCaseTime = iterate("0-59,0-13,2,3,4,5 17-19 22-23,22,23 2,3 *", baseTime, time, count, true);
            System.out.println("Worst case with parsing took " + worstCaseTime + "ms for " + count + " iterations. (" + (worstCaseTime / (float) count) + "ms per call)");

            // Test the best-case scenario without parsing the expression on each iteration
            bestCaseTime = iterate("* * * * *", baseTime, time, count, false);
            System.out.println("Best case without parsing took " + bestCaseTime + "ms for " + count + " iterations. (" + (bestCaseTime / (float) count) + "ms per call)");

            // Test a near worst-case scenario without parsing the expression on each iteration
            worstCaseTime = iterate("0-59,0-13,2,3,4,5 17-19 22-23,22,23 2,3 *", baseTime, time, count, false);
            System.out.println("Worst case without parsing took " + worstCaseTime + "ms for " + count + " iterations. (" + (worstCaseTime / (float) count) + "ms per call)");
        } catch (ParseException e) {
        }
    }

    /**
    * Tests that a range of valid cron expressions get parsed correctly.
    */
    public void testValidExpressionParsing() {
        FastCronParser parser;

        // Check the default constructor
        parser = new FastCronParser();
        assertNull(parser.getCronExpression());

        try {
            parser = new FastCronParser("* * * * *");
            assertEquals("* * * * *", parser.getCronExpression()); // Should be the same as what we gave it
            assertEquals("* * * * *", parser.getExpressionSummary());

            parser.setCronExpression("0  *  * *     *");
            assertEquals("0  *  * *     *", parser.getCronExpression()); // Should be the same as what we gave it
            assertEquals("0 * * * *", parser.getExpressionSummary());

            parser.setCronExpression("5 10 * * 1,4,6");
            assertEquals("5 10 * * 1,4,6", parser.getExpressionSummary());

            parser.setCronExpression("0,5-20,4-15,24-27 0 *   2-4,5,6-3 *"); // Overlapping ranges, backwards ranges
            assertEquals("0,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,24,25,26,27 0 * 2,3,4,5,6 *", parser.getExpressionSummary());
        } catch (ParseException e) {
            e.printStackTrace();
            fail("Cron expression should have been valid: " + e);
        }
    }

    /**
    * Makes a call to the FastCronParser.
    *
    * @param dateStr   The date string to use as the base date. The format must be
    * <code>"dd/MM/yyyy HH:mm"</code>.
    * @param cronExpr  The cron expression to test.
    * @param result    The expected result. This should be a date in the same format
    * as <code>dateStr</code>.
    * @param expectException Pass in <code>true</code> if the {@link FastCronParser} is
    * expected to throw a <code>ParseException</code>.
    */
    private void cronCall(String dateStr, String cronExpr, String result, boolean expectException) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
        Date date = null;

        try {
            date = sdf.parse(dateStr);
        } catch (ParseException e) {
            fail("Failed to parse date " + dateStr + ". Please check your unit test code!");
        }

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);

        long baseTime = calendar.getTimeInMillis();
        FastCronParser parser = null;

        try {
            parser = new FastCronParser(cronExpr);

            if (expectException) {
                fail("Should have received a ParseException while parsing " + cronExpr);
            }

            long time = parser.getTimeBefore(baseTime);
            assertEquals(result, sdf.format(new Date(time)));
        } catch (ParseException e) {
            if (!expectException) {
                fail("Unexpected ParseException while parsing " + cronExpr + ": " + e);
            }
        }
    }

    /**
    * Used by the benchmarking
    */
    private long iterate(String cronExpr, long baseTime, long time, int count, boolean withParse) throws ParseException {
        long startTime = System.currentTimeMillis();

        if (withParse) {
            FastCronParser parser = new FastCronParser();

            for (int i = 0; i < count; i++) {
                parser.setCronExpression(cronExpr);
                time = parser.getTimeBefore(baseTime);
            }
        } else {
            FastCronParser parser = new FastCronParser(cronExpr);

            for (int i = 0; i < count; i++) {
                time = parser.getTimeBefore(baseTime);
            }
        }

        long endTime = System.currentTimeMillis();
        long duration = (endTime - startTime);
        duration += (time - time); // Use the time variable to prevent it getting optimized away
        return duration;
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人综合在线观看| 久久免费国产精品| 日韩一级二级三级精品视频| 国产精品国产三级国产a| 国产精品久久久久久亚洲毛片| 亚洲欧洲美洲综合色网| 午夜免费久久看| 国内精品久久久久影院薰衣草 | 欧美日韩一区不卡| 日韩一区二区在线观看视频 | 日韩欧美自拍偷拍| 国产精品久久久久久久裸模| 亚洲高清久久久| 国产麻豆精品视频| 欧美亚洲综合另类| 久久久久久久一区| 亚洲成人在线网站| 国产精品一品视频| 欧美日韩国产另类一区| 欧美韩国日本不卡| 日韩精品三区四区| 99在线视频精品| 日韩欧美一级二级| 亚洲精品五月天| 国产在线国偷精品免费看| 在线视频中文字幕一区二区| 久久一留热品黄| 五月婷婷久久丁香| 99这里只有久久精品视频| 精品国产污污免费网站入口 | 欧美亚洲综合在线| 国产精品麻豆一区二区| 六月丁香综合在线视频| 日本高清无吗v一区| 国产三区在线成人av| 午夜精品久久久久影视| 97精品电影院| 色综合天天综合在线视频| 蜜桃视频在线观看一区| 99久久精品国产导航| 2021国产精品久久精品| 婷婷六月综合网| 色综合中文字幕国产 | 69堂成人精品免费视频| 国产蜜臀av在线一区二区三区| 亚洲国产成人av| 成+人+亚洲+综合天堂| 精品1区2区在线观看| 亚洲国产日产av| 91一区二区在线| 日本一区二区三区四区在线视频 | 日韩欧美的一区二区| 亚洲影视资源网| 99久久精品久久久久久清纯| 国产色产综合色产在线视频 | 国产亚洲精久久久久久| 麻豆91在线观看| 欧美一区二区三区在线看| 国产成人免费高清| 精品成人在线观看| 麻豆91在线播放免费| 日韩激情视频在线观看| 色综合 综合色| 欧美精品一区二区三区蜜臀| 欧美日韩精品一区二区| 亚洲国产高清aⅴ视频| 国内精品嫩模私拍在线| 日韩一区二区免费在线观看| 天天综合网 天天综合色| 色视频一区二区| 亚洲精品国产成人久久av盗摄| www.亚洲激情.com| 国产精品不卡在线| 99视频热这里只有精品免费| 国产精品久久久久影视| 成人app在线| 亚洲素人一区二区| 色婷婷综合五月| 一区二区三区在线视频观看58| 91久久精品国产91性色tv| 亚洲精品va在线观看| 欧美性欧美巨大黑白大战| 亚洲一区国产视频| 欧美日韩国产精选| 日本aⅴ免费视频一区二区三区 | 亚洲午夜精品久久久久久久久| 色婷婷av一区| 香蕉乱码成人久久天堂爱免费| 欧美日韩精品欧美日韩精品一| 亚洲欧美欧美一区二区三区| 欧美精品 日韩| 天堂va蜜桃一区二区三区| 不卡电影免费在线播放一区| 精品伦理精品一区| 国产麻豆视频一区二区| 国产精品久久久久久一区二区三区 | 狠狠色丁香久久婷婷综合丁香| 亚洲精品一区二区三区香蕉| 国产成人在线视频播放| 亚洲欧洲成人自拍| 欧美日韩在线播| 久久99久久99精品免视看婷婷 | 国产成人a级片| 中文字幕一区二区三区在线不卡 | 日韩电影在线观看一区| 精品不卡在线视频| av电影天堂一区二区在线| 亚洲一二三区在线观看| 日韩欧美一级二级| 成人手机在线视频| 亚洲成人av电影在线| 国产精品久久夜| 欧美一级淫片007| 91福利视频网站| 色婷婷久久99综合精品jk白丝| 2020国产精品自拍| eeuss鲁片一区二区三区| 亚洲成人一二三| 久久久久久电影| 色婷婷久久久久swag精品| 久久国内精品自在自线400部| 国产日韩欧美制服另类| 在线精品视频免费播放| 黄色小说综合网站| 亚洲欧美色综合| 精品免费日韩av| 色噜噜狠狠一区二区三区果冻| 蜜芽一区二区三区| 亚洲欧美怡红院| 欧美大片一区二区| 色噜噜狠狠色综合欧洲selulu| 国产综合一区二区| 亚洲一区二区三区国产| 久久久青草青青国产亚洲免观| 色婷婷综合久久久久中文一区二区 | 久久精品国产免费看久久精品| 中文字幕中文乱码欧美一区二区| 91精品免费在线观看| av成人免费在线观看| 激情文学综合插| 亚洲麻豆国产自偷在线| 男女激情视频一区| 久久99在线观看| 91久久精品国产91性色tv| 日韩精品一区第一页| 国产精品三级久久久久三级| 制服丝袜日韩国产| 一本到一区二区三区| 国内精品久久久久影院色 | 日本韩国欧美在线| 国产成人av电影在线播放| 日韩专区中文字幕一区二区| 亚洲人成小说网站色在线| 久久久不卡影院| 日韩欧美一卡二卡| 欧美久久久久久久久久| 色先锋久久av资源部| 9色porny自拍视频一区二区| 另类人妖一区二区av| 视频一区二区国产| 亚洲在线免费播放| 亚洲三级在线免费| 国产精品视频在线看| 久久精品亚洲麻豆av一区二区| 欧美一区二区黄| 欧美另类久久久品| 欧美少妇性性性| 在线免费观看不卡av| 成人av资源站| 高清在线成人网| 国产高清久久久久| 国产精品影音先锋| 国产米奇在线777精品观看| 美国三级日本三级久久99| 亚洲一卡二卡三卡四卡五卡| 精品成人a区在线观看| 国产麻豆成人精品| 亚洲女爱视频在线| 欧美一级在线观看| 欧美一区二区久久| 欧美精品日韩一区| 欧美伦理电影网| 91精品国产综合久久久久久久久久| 91国模大尺度私拍在线视频| 97久久超碰国产精品电影| 99久久精品情趣| 色域天天综合网| 欧美三级视频在线观看| 国产校园另类小说区| 91视频在线观看| 91女厕偷拍女厕偷拍高清| 97国产一区二区| 色综合天天综合色综合av | 国产精品成人午夜| 亚洲女同一区二区| 亚洲一卡二卡三卡四卡五卡| 视频一区在线视频| 老司机免费视频一区二区三区| 国产成人h网站| 91在线国内视频|