Skip to content

Commit

Permalink
test: DbInsertDuplicate2Test: Added end-check
Browse files Browse the repository at this point in the history
  • Loading branch information
hishidama committed Apr 4, 2024
1 parent bb6b1ec commit 12e6bbb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tsurugidb.iceaxe.test.insert;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
Expand Down Expand Up @@ -86,6 +87,13 @@ void occ() throws Exception {
test(setting, 30, 500, false);
}

@Test
@DisabledIfEnvironmentVariable(named = "ICEAXE_DBTEST_DISABLE", matches = ".*DbInsertDuplicate2Test-occDebug.*")
void occDebug() throws Exception {
var setting = TgTmSetting.ofAlways(TgTxOption.ofOCC());
test(setting, 30, 500, true);
}

@Test
@DisabledIfEnvironmentVariable(named = "ICEAXE_DBTEST_DISABLE", matches = ".*DbInsertDuplicate2Test-ltx.*")
void ltx() throws Exception {
Expand Down Expand Up @@ -258,6 +266,15 @@ public Void call() throws Exception {
}
counter.incrementAndGet();
}

synchronized (OnlineTask.class) {
if (!stopFlag.get()) {
String label = String.format("th%d-endCheck", threadNumber);
if (!debugExecute(label, debugTm, debugSelect1Ps, debugSelect2Ps)) {
stopFlag.set(true);
}
}
}
}
return null;
}
Expand All @@ -267,11 +284,13 @@ private void execute(TsurugiTransaction transaction, TsurugiSqlQuery<Integer> ma
int foo = transaction.executeAndFindRecord(maxPs).get();

var entity = new TestEntity(foo, foo, label);
transaction.executeAndGetCount(insertPs, entity);
int count1 = transaction.executeAndGetCount(insertPs, entity);
assertEquals(1, count1);

for (int i = 0; i < 10; i++) {
var parameter = TgBindParameters.of(vKey1.bind(foo), vKey2.bind(i + 1), vZzz2.bind(label));
transaction.executeAndGetCount(insert2Ps, parameter);
int count2 = transaction.executeAndGetCount(insert2Ps, parameter);
assertEquals(1, count2);
}
}

Expand All @@ -281,13 +300,13 @@ private boolean debugExecute(String label, TsurugiTransactionManager tm, Tsurugi
var list2 = new ArrayList<TsurugiResultEntity>();
TgTxOption[] debugTxOption = { null };
tm.execute(transaction -> {
list1.clear();
list2.clear();
if (stopFlag.get()) {
transaction.rollback();
return;
}

list1.clear();
list2.clear();
list1.addAll(transaction.executeAndGetList(select1Ps));
list2.addAll(transaction.executeAndGetList(select2Ps));
debugTxOption[0] = transaction.getTransactionOption();
Expand Down Expand Up @@ -380,7 +399,7 @@ private void debugLog(String label, List<TestEntity> list1, List<TsurugiResultEn
LOG.error("{}: test.size={}, test2.size={}, readTxOption={}", label, list1.size(), list2.size(), txOption);

for (var c : invalidList) {
LOG.error("{}: {}", label, c);
LOG.error("{} error data: {}", label, c);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tsurugidb.iceaxe.test.insert;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
Expand Down Expand Up @@ -251,6 +252,15 @@ public Void call() throws Exception {
throw e;
}
}

synchronized (OnlineTask.class) {
if (!stopFlag.get()) {
String label = String.format("th%d-endCheck", threadNumber);
if (!debugExecute(label, debugTm, debugSelect1Ps, debugSelect2Ps)) {
stopFlag.set(true);
}
}
}
}
return null;
}
Expand All @@ -261,27 +271,30 @@ private void execute(TsurugiTransaction transaction, TsurugiSqlQuery<TsurugiResu
int foo = max.getInt("foo");

var entity = new TestEntity(foo, foo, label);
transaction.executeAndGetCount(insertPs, entity);
int count1 = transaction.executeAndGetCount(insertPs, entity);
assertEquals(1, count1);

var parameter = TgBindParameters.of(vKey1.bind(foo), vKey2.bind(foo / 2), vZzz2.bind(label));
transaction.executeAndGetCount(insert2Ps, parameter);
int count2 = transaction.executeAndGetCount(insert2Ps, parameter);
assertEquals(1, count2);
}

private boolean debugExecute(String label, TsurugiTransactionManager tm, TsurugiSqlQuery<TestEntity> select1Ps, TsurugiSqlQuery<TsurugiResultEntity> select2Ps)
throws IOException, InterruptedException {
var list1 = new ArrayList<TestEntity>();
var list2 = new ArrayList<TsurugiResultEntity>();
tm.execute(transaction -> {
list1.clear();
list2.clear();
if (stopFlag.get()) {
transaction.rollback();
return;
}

list1.clear();
list2.clear();
list1.addAll(transaction.executeAndGetList(select1Ps));
list2.addAll(transaction.executeAndGetList(select2Ps));
});

for (int i = 0; i < Math.max(list1.size(), list2.size()); i++) {
if (i >= list1.size() || i >= list2.size()) {
debugLog(label, list1, list2, i);
Expand Down

0 comments on commit 12e6bbb

Please sign in to comment.