Search in sources :

Example 1 with TimeoutDetector

use of com.ctrip.platform.dal.dao.markdown.TimeoutDetector in project dal by ctripcorp.

the class TimeoutDetectorTest method countBaseLineMatchButOverdueTest.

@Test
public void countBaseLineMatchButOverdueTest() {
    TimeoutDetector detector = new TimeoutDetector();
    DalStatusManager.getTimeoutMarkdown().setEnabled(true);
    DalStatusManager.getTimeoutMarkdown().setErrorCountThreshold(5);
    DalStatusManager.getTimeoutMarkdown().setSamplingDuration(1);
    for (int i = 0; i < 10; i++) {
        SQLException e = this.mockNotTimeoutException();
        DatabaseCategory ct = DatabaseCategory.MySql;
        if (i % 2 == 0) {
            ct = random.nextBoolean() ? DatabaseCategory.MySql : DatabaseCategory.SqlServer;
            e = this.mockTimeoutException(ct);
        }
        if (i == 4) {
            try {
                Thread.sleep(1100);
            } catch (InterruptedException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
        ErrorContext ctx = new ErrorContext(dbName, ct, 1000, e);
        detector.detect(ctx);
    }
    Assert.assertFalse(MarkdownManager.isMarkdown(dbName));
}
Also used : DatabaseCategory(com.ctrip.platform.dal.common.enums.DatabaseCategory) SQLException(java.sql.SQLException) ErrorContext(com.ctrip.platform.dal.dao.markdown.ErrorContext) TimeoutDetector(com.ctrip.platform.dal.dao.markdown.TimeoutDetector) Test(org.junit.Test)

Example 2 with TimeoutDetector

use of com.ctrip.platform.dal.dao.markdown.TimeoutDetector in project dal by ctripcorp.

the class TimeoutDetectorTest method errorPercentMatchTest.

@Test
public void errorPercentMatchTest() {
    TimeoutDetector detector = new TimeoutDetector();
    DalStatusManager.getTimeoutMarkdown().setEnabled(true);
    DalStatusManager.getMarkdownStatus().setEnableAutoMarkdown(true);
    DalStatusManager.getTimeoutMarkdown().setErrorPercentReferCount(10);
    DalStatusManager.getTimeoutMarkdown().setErrorPercentThreshold(0.5f);
    for (int i = 0; i < 10; i++) {
        SQLException e = this.mockNotTimeoutException();
        DatabaseCategory ct = DatabaseCategory.MySql;
        if (i % 2 == 0) {
            ct = random.nextBoolean() ? DatabaseCategory.MySql : DatabaseCategory.SqlServer;
            e = this.mockTimeoutException(ct);
        }
        ErrorContext ctx = new ErrorContext(dbName, ct, 1000, e);
        detector.detect(ctx);
    }
    Assert.assertTrue(MarkdownManager.isMarkdown(dbName));
}
Also used : DatabaseCategory(com.ctrip.platform.dal.common.enums.DatabaseCategory) SQLException(java.sql.SQLException) ErrorContext(com.ctrip.platform.dal.dao.markdown.ErrorContext) TimeoutDetector(com.ctrip.platform.dal.dao.markdown.TimeoutDetector) Test(org.junit.Test)

Example 3 with TimeoutDetector

use of com.ctrip.platform.dal.dao.markdown.TimeoutDetector in project dal by ctripcorp.

the class TimeoutDetectorTest method countBaseLineMatchTest.

@Test
public void countBaseLineMatchTest() {
    TimeoutDetector detector = new TimeoutDetector();
    DalStatusManager.getMarkdownStatus().setEnableAutoMarkdown(true);
    DalStatusManager.getTimeoutMarkdown().setEnabled(true);
    DalStatusManager.getTimeoutMarkdown().setErrorCountThreshold(5);
    for (int i = 0; i < 10; i++) {
        SQLException e = this.mockNotTimeoutException();
        DatabaseCategory ct = DatabaseCategory.MySql;
        if (i % 2 == 0) {
            ct = random.nextBoolean() ? DatabaseCategory.MySql : DatabaseCategory.SqlServer;
            e = this.mockTimeoutException(ct);
        }
        ErrorContext ctx = new ErrorContext(dbName, ct, 1000, e);
        detector.detect(ctx);
    }
    Assert.assertTrue(MarkdownManager.isMarkdown(dbName));
}
Also used : DatabaseCategory(com.ctrip.platform.dal.common.enums.DatabaseCategory) SQLException(java.sql.SQLException) ErrorContext(com.ctrip.platform.dal.dao.markdown.ErrorContext) TimeoutDetector(com.ctrip.platform.dal.dao.markdown.TimeoutDetector) Test(org.junit.Test)

Aggregations

DatabaseCategory (com.ctrip.platform.dal.common.enums.DatabaseCategory)3 ErrorContext (com.ctrip.platform.dal.dao.markdown.ErrorContext)3 TimeoutDetector (com.ctrip.platform.dal.dao.markdown.TimeoutDetector)3 SQLException (java.sql.SQLException)3 Test (org.junit.Test)3