-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
227 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
modules/kvs/src/inttest/java/com/tsurugidb/tsubakuro/kvs/basic/GetTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.tsurugidb.tsubakuro.kvs.basic; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.tsurugidb.tsubakuro.kvs.KvsClient; | ||
import com.tsurugidb.tsubakuro.kvs.KvsServiceCode; | ||
import com.tsurugidb.tsubakuro.kvs.KvsServiceException; | ||
import com.tsurugidb.tsubakuro.kvs.RecordBuffer; | ||
import com.tsurugidb.tsubakuro.kvs.util.TestBase; | ||
|
||
public class GetTest extends TestBase { | ||
|
||
private static final String TABLE_NAME = "table" + GetTest.class.getSimpleName(); | ||
private static final String KEY_NAME = "k1"; | ||
private static final String VALUE_NAME = "v1"; | ||
|
||
public GetTest() throws Exception { | ||
String schema = String.format("%s BIGINT PRIMARY KEY, %s BIGINT", KEY_NAME, VALUE_NAME); | ||
createTable(TABLE_NAME, schema); | ||
} | ||
|
||
@Test | ||
public void invalidRequests() throws Exception { | ||
final long key1 = 1L; | ||
final long value1 = 100L; | ||
RecordBuffer key = new RecordBuffer(); | ||
try (var session = getNewSession(); var kvs = KvsClient.attach(session)) { | ||
// COLUMN_TYPE_MISMATCH | ||
try (var tx = kvs.beginTransaction().await()) { | ||
key.clear(); | ||
key.add(KEY_NAME, (int)key1); | ||
KvsServiceException ex = assertThrows(KvsServiceException.class, | ||
() -> kvs.get(tx, TABLE_NAME, key).await()); | ||
assertEquals(KvsServiceCode.COLUMN_TYPE_MISMATCH, ex.getDiagnosticCode()); | ||
kvs.rollback(tx).await(); | ||
} | ||
try (var tx = kvs.beginTransaction().await()) { | ||
key.clear(); | ||
key.add(KEY_NAME, "aaa"); | ||
KvsServiceException ex = assertThrows(KvsServiceException.class, | ||
() -> kvs.get(tx, TABLE_NAME, key).await()); | ||
assertEquals(KvsServiceCode.COLUMN_TYPE_MISMATCH, ex.getDiagnosticCode()); | ||
kvs.rollback(tx).await(); | ||
} | ||
// COLUMN_NOT_FOUND | ||
try (var tx = kvs.beginTransaction().await()) { | ||
key.clear(); | ||
key.add("hoge", key1); | ||
KvsServiceException ex = assertThrows(KvsServiceException.class, | ||
() -> kvs.get(tx, TABLE_NAME, key).await()); | ||
assertEquals(KvsServiceCode.COLUMN_NOT_FOUND, ex.getDiagnosticCode()); | ||
kvs.rollback(tx).await(); | ||
} | ||
try (var tx = kvs.beginTransaction().await()) { | ||
key.clear(); | ||
key.add(KEY_NAME, key1); | ||
key.add("hoge", key1); | ||
KvsServiceException ex = assertThrows(KvsServiceException.class, | ||
() -> kvs.get(tx, TABLE_NAME, key).await()); | ||
assertEquals(KvsServiceCode.COLUMN_NOT_FOUND, ex.getDiagnosticCode()); | ||
kvs.rollback(tx).await(); | ||
} | ||
// INVALID_ARGUMENT | ||
try (var tx = kvs.beginTransaction().await()) { | ||
key.clear(); | ||
// empty key | ||
KvsServiceException ex = assertThrows(KvsServiceException.class, | ||
() -> kvs.get(tx, TABLE_NAME, key).await()); | ||
assertEquals(KvsServiceCode.INVALID_ARGUMENT, ex.getDiagnosticCode()); | ||
kvs.rollback(tx).await(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.