use of com.ctrip.platform.dal.common.enums.DatabaseCategory 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));
}
use of com.ctrip.platform.dal.common.enums.DatabaseCategory 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));
}
use of com.ctrip.platform.dal.common.enums.DatabaseCategory 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));
}
use of com.ctrip.platform.dal.common.enums.DatabaseCategory 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));
}
use of com.ctrip.platform.dal.common.enums.DatabaseCategory 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));
}
Aggregations