Search in sources :

Example 1 with ErrorContext

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

the class TimeoutDetectorTest method isTimeOutExceptionTest.

@Test
public void isTimeOutExceptionTest() {
    DatabaseCategory ct = DatabaseCategory.MySql;
    SQLException e = this.mockTimeoutException(ct);
    ErrorContext ctx = new ErrorContext(dbName, ct, 10000, e);
    Assert.assertTrue(TimeoutDetector.isTimeOutException(ctx));
    ct = DatabaseCategory.SqlServer;
    e = this.mockTimeoutException(ct);
    ctx = new ErrorContext(dbName, ct, 10000, e);
    Assert.assertTrue(TimeoutDetector.isTimeOutException(ctx));
    ct = DatabaseCategory.SqlServer;
    e = new SQLException("查询超时");
    ctx = new ErrorContext(dbName, ct, 10000, e);
    Assert.assertTrue(TimeoutDetector.isTimeOutException(ctx));
    ct = DatabaseCategory.MySql;
    e = this.mockNotTimeoutException();
    ctx = new ErrorContext(dbName, ct, 10000, e);
    Assert.assertFalse(TimeoutDetector.isTimeOutException(ctx));
}
Also used : DatabaseCategory(com.ctrip.platform.dal.common.enums.DatabaseCategory) SQLException(java.sql.SQLException) ErrorContext(com.ctrip.platform.dal.dao.markdown.ErrorContext) Test(org.junit.Test)

Example 2 with ErrorContext

use of com.ctrip.platform.dal.dao.markdown.ErrorContext 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 3 with ErrorContext

use of com.ctrip.platform.dal.dao.markdown.ErrorContext 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 4 with ErrorContext

use of com.ctrip.platform.dal.dao.markdown.ErrorContext 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)4 ErrorContext (com.ctrip.platform.dal.dao.markdown.ErrorContext)4 SQLException (java.sql.SQLException)4 Test (org.junit.Test)4 TimeoutDetector (com.ctrip.platform.dal.dao.markdown.TimeoutDetector)3