diff --git a/src/main/java/io/codenotary/immudb4j/exceptions/CorruptedDataException.java b/src/main/java/io/codenotary/immudb4j/Database.java similarity index 53% rename from src/main/java/io/codenotary/immudb4j/exceptions/CorruptedDataException.java rename to src/main/java/io/codenotary/immudb4j/Database.java index 52fc089..b5510a9 100644 --- a/src/main/java/io/codenotary/immudb4j/exceptions/CorruptedDataException.java +++ b/src/main/java/io/codenotary/immudb4j/Database.java @@ -13,10 +13,31 @@ See the License for the specific language governing permissions and limitations under the License. */ -package io.codenotary.immudb4j.exceptions; +package io.codenotary.immudb4j; -public class CorruptedDataException extends Exception { +import io.codenotary.immudb.ImmudbProto; - private static final long serialVersionUID = 1L; +public class Database { + private String name; + private boolean loaded; + + private Database() {} + + public static Database valueOf(ImmudbProto.DatabaseWithSettings pdb) { + final Database db = new Database(); + + db.name = pdb.getName(); + db.loaded = pdb.getLoaded(); + + return db; + } + + public String getName() { + return name; + } + + public boolean isLoaded() { + return loaded; + } } diff --git a/src/main/java/io/codenotary/immudb4j/ImmuClient.java b/src/main/java/io/codenotary/immudb4j/ImmuClient.java index e435556..8cc2487 100644 --- a/src/main/java/io/codenotary/immudb4j/ImmuClient.java +++ b/src/main/java/io/codenotary/immudb4j/ImmuClient.java @@ -78,7 +78,7 @@ public class ImmuClient { private Session session; private Timer sessionHeartBeat; - public ImmuClient(Builder builder) { + private ImmuClient(Builder builder) { stateHolder = builder.getStateHolder(); serverSigningKey = builder.getServerSigningKey(); keepAlivePeriod = builder.getKeepAlivePeriod(); @@ -94,10 +94,17 @@ public ImmuClient(Builder builder) { nonBlockingStub = ImmuServiceGrpc.newStub(channel); } + /** + * @return ImmuClient builder for chaining client settings + */ public static Builder newBuilder() { return new Builder(); } + /** + * Releases the resources used by the SDK objects. (e.g. connection resources). + * This method should be called just before the existing process ends. + */ public synchronized void shutdown() throws InterruptedException { if (channel == null) { return; @@ -118,6 +125,13 @@ protected synchronized Session getSession() { return session; } + /** + * Establishes a new database session using provided credentials + * + * @param database The name of the database to which the session is established + * @param username The username is required to get authorization + * @param password The password is required to get authorization + */ public synchronized void openSession(String database, String username, String password) { if (session != null) { throw new IllegalStateException("session already opened"); @@ -152,6 +166,9 @@ public void run() { }, 0, keepAlivePeriod); } + /** + * Closes the open database session + */ public synchronized void closeSession() { if (session == null) { throw new IllegalStateException("no open session"); @@ -216,6 +233,13 @@ public synchronized ImmuState currentState() throws VerificationException { // ========== SQL ========== // + /** + * Creates a new SQL transaction that can be terminated with the + * {@link #commitTransaction() commit} or {@link #rollbackTransaction() + * rollback} methods + * + * @throws SQLException if the cause of the error is sql-related + */ public synchronized void beginTransaction() throws SQLException { if (session == null) { throw new IllegalStateException("no open session"); @@ -234,6 +258,11 @@ public synchronized void beginTransaction() throws SQLException { session.setTransactionID(res.getTransactionID()); } + /** + * Commits the ongoing SQL transaction + * + * @throws SQLException if the cause of the error is sql-related + */ public synchronized void commitTransaction() throws SQLException { if (session == null) { throw new IllegalStateException("no open session"); @@ -245,9 +274,14 @@ public synchronized void commitTransaction() throws SQLException { blockingStub.commit(Empty.getDefaultInstance()); - session.setTransactionID( null); + session.setTransactionID(null); } + /** + * Rollback the ongoing SQL transaction + * + * @throws SQLException if the cause of the error is sql-related + */ public synchronized void rollbackTransaction() throws SQLException { if (session == null) { throw new IllegalStateException("no open session"); @@ -262,10 +296,26 @@ public synchronized void rollbackTransaction() throws SQLException { session.setTransactionID(null); } + /** + * Executes a SQL statement in the ongoing SQL transaction + * + * @param stmt the SQL statement to be executed + * @param params the positional parameters for SQL statement evaluation + * + * @throws SQLException if the cause of the error is sql-related + */ public void sqlExec(String stmt, SQLValue... params) throws SQLException { sqlExec(stmt, sqlNameParams(params)); } + /** + * Executes a SQL statement in the ongoing SQL transaction + * + * @param stmt the SQL statement to be executed + * @param params the named parameters for SQL statement evaluation + * + * @throws SQLException if the cause of the error is sql-related + */ public synchronized void sqlExec(String stmt, Map params) throws SQLException { if (session == null) { throw new IllegalStateException("no open session"); @@ -283,10 +333,30 @@ public synchronized void sqlExec(String stmt, Map params) thro blockingStub.txSQLExec(req); } + /** + * Performs a SQL query in the ongoing SQL transaction + * + * @param stmt the SQL query to be evaluated + * @param params the positional parameters for SQL statement evaluation + * + * @return the query resultset + * + * @throws SQLException if the cause of the error is sql-related + */ public SQLQueryResult sqlQuery(String stmt, SQLValue... params) throws SQLException { return sqlQuery(stmt, sqlNameParams(params)); } + /** + * Performs a SQL query in the ongoing SQL transaction + * + * @param stmt the SQL query to be evaluated + * @param params the named parameters for SQL statement evaluation + * + * @return the query resultset + * + * @throws SQLException if the cause of the error is sql-related + */ public synchronized SQLQueryResult sqlQuery(String stmt, Map params) throws SQLException { if (session == null) { throw new IllegalStateException("no open session"); @@ -308,7 +378,7 @@ private Map sqlNameParams(SQLValue... params) { final Map nparams = new HashMap<>(params.length); for (int i = 1; i <= params.length; i++) { - nparams.put("param" + i, params[i-1]); + nparams.put("param" + i, params[i - 1]); } return nparams; @@ -319,10 +389,9 @@ private Iterable sqlEncodeParams(Map params) { for (Map.Entry p : params.entrySet()) { nparams.add(NamedParam.newBuilder() - .setName(p.getKey()) - .setValue(p.getValue().asProtoSQLValue()) - .build() - ); + .setName(p.getKey()) + .setValue(p.getValue().asProtoSQLValue()) + .build()); } return nparams; @@ -332,10 +401,21 @@ private Iterable sqlEncodeParams(Map params) { // ========== DATABASE ========== // + /** + * Creates a database using default settings + * + * @param database the database name + */ public void createDatabase(String database) { createDatabase(database, false); } + /** + * Creates a database using default settings + * + * @param database the database name + * @param ifNotExists allow the database to be already created + */ public synchronized void createDatabase(String database, boolean ifNotExists) { if (session == null) { throw new IllegalStateException("no open session"); @@ -349,12 +429,16 @@ public synchronized void createDatabase(String database, boolean ifNotExists) { blockingStub.createDatabaseV2(req); } - // LoadDatabase loads database on the server. A database is not loaded - // if it has AutoLoad setting set to false or if it failed to load during - // immudb startup. - // - // This call requires SysAdmin permission level or admin permission to the - // database. + /** + * Loads database on the server. A database is not loaded + * if it has AutoLoad setting set to false or if it failed to load during immudb + * startup. + * + * This call requires SysAdmin permission level or admin permission to the + * database. + * + * @param database the database name + */ public synchronized void loadDatabase(String database) { if (session == null) { throw new IllegalStateException("no open session"); @@ -367,13 +451,15 @@ public synchronized void loadDatabase(String database) { blockingStub.loadDatabase(req); } - // UnloadDatabase unloads database on the server. Such database becomes - // inaccessible - // by the client and server frees internal resources allocated for that - // database. - // - // This call requires SysAdmin permission level or admin permission to the - // database. + /** + * Unloads database on the server. Such database becomes inaccessible by the + * client and server frees internal resources allocated for that database. + * + * This call requires SysAdmin permission level or admin permission to the + * database. + * + * @param database the database name + */ public synchronized void unloadDatabase(String database) { if (session == null) { throw new IllegalStateException("no open session"); @@ -386,11 +472,15 @@ public synchronized void unloadDatabase(String database) { blockingStub.unloadDatabase(req); } - // DeleteDatabase removes an unloaded database. - // This also removes locally stored files used by the database. - // - // This call requires SysAdmin permission level or admin permission to the - // database. + /** + * Removes an unloaded database. This also removes locally stored files used by + * the database. + * + * This call requires SysAdmin permission level or admin permission to the + * database. + * + * @param database the database name + */ public synchronized void deleteDatabase(String database) { if (session == null) { throw new IllegalStateException("no open session"); @@ -403,7 +493,10 @@ public synchronized void deleteDatabase(String database) { blockingStub.deleteDatabase(req); } - public synchronized List databases() { + /** + * @return the list of existing databases + */ + public synchronized List databases() { if (session == null) { throw new IllegalStateException("no open session"); } @@ -411,10 +504,10 @@ public synchronized List databases() { final ImmudbProto.DatabaseListRequestV2 req = ImmudbProto.DatabaseListRequestV2.newBuilder().build(); final ImmudbProto.DatabaseListResponseV2 resp = blockingStub.databaseListV2(req); - final List list = new ArrayList<>(resp.getDatabasesCount()); + final List list = new ArrayList<>(resp.getDatabasesCount()); for (ImmudbProto.DatabaseWithSettings db : resp.getDatabasesList()) { - list.add(db.getName()); + list.add(Database.valueOf(db)); } return list; @@ -424,18 +517,36 @@ public synchronized List databases() { // ========== GET ========== // + /** + * @param key the key to look for + * @return the latest entry associated to the provided key + */ public Entry get(String key) throws KeyNotFoundException { return get(Utils.toByteArray(key)); } + /** + * @param key the key to look for + * @return the latest entry associated to the provided key + */ public Entry get(byte[] key) throws KeyNotFoundException { return getAtTx(key, 0); } + /** + * @param key the key to look for + * @param tx the transaction at which the associated entry is expected to be + * @return the entry associated to the provided key and transaction + */ public Entry getAtTx(String key, long tx) throws KeyNotFoundException { return getAtTx(Utils.toByteArray(key), tx); } + /** + * @param key the key to look for + * @param tx the transaction at which the associated entry is expected to be + * @return the entry associated to the provided key and transaction + */ public synchronized Entry getAtTx(byte[] key, long tx) throws KeyNotFoundException { final ImmudbProto.KeyRequest req = ImmudbProto.KeyRequest.newBuilder() .setKey(Utils.toByteString(key)) @@ -453,10 +564,32 @@ public synchronized Entry getAtTx(byte[] key, long tx) throws KeyNotFoundExcepti } } + /** + * This method can be used to avoid additional latency while the server + * waits for the indexer to finish indexing but still guarantees that + * specific portion of the database history has already been indexed. + * + * @param key the key to look for + * @param tx the lowest transaction from which the associated entry should be + * retrieved + * @return the latest indexed entry associated the to provided key. Ensuring the + * indexing has already be completed up to the specified transaction. + */ public Entry getSinceTx(String key, long tx) throws KeyNotFoundException { return getSinceTx(Utils.toByteArray(key), tx); } + /** + * This method can be used to avoid additional latency while the server + * waits for the indexer to finish indexing but still guarantees that + * specific portion of the database history has already been indexed. + * + * @param key the key to look for + * @param tx the lowest transaction from which the associated entry should be + * retrieved + * @return the latest indexed entry associated the to provided key. Ensuring the + * indexing has already be completed up to the specified transaction. + */ public synchronized Entry getSinceTx(byte[] key, long tx) throws KeyNotFoundException { final ImmudbProto.KeyRequest req = ImmudbProto.KeyRequest.newBuilder() .setKey(Utils.toByteString(key)) @@ -474,10 +607,46 @@ public synchronized Entry getSinceTx(byte[] key, long tx) throws KeyNotFoundExce } } + /** + * @param key the key to look for + * @param rev the specific revision + * @return the specific revision for given key. + * + * Key revision is an integer value that starts at 1 when + * the key is created and then increased by 1 on every update made to + * that key. + * + * The way rev is interpreted depends on the value: + * - if rev == 0, returns current value + * - if rev > 0, returns nth revision value, e.g. 1 is the first + * value, + * 2 is the second and so on + * - if rev < 0, returns nth revision value from the end, e.g. -1 is + * the + * previous value, -2 is the one before and so on + */ public Entry getAtRevision(String key, long rev) throws KeyNotFoundException { return getAtRevision(Utils.toByteArray(key), rev); } + /** + * @param key the key to look for + * @param rev the specific revision + * @return the specific revision for given key. + * + * Key revision is an integer value that starts at 1 when + * the key is created and then increased by 1 on every update made to + * that key. + * + * The way rev is interpreted depends on the value: + * - if rev == 0, returns current value + * - if rev > 0, returns nth revision value, e.g. 1 is the first + * value, + * 2 is the second and so on + * - if rev < 0, returns nth revision value from the end, e.g. -1 is + * the + * previous value, -2 is the one before and so on + */ public synchronized Entry getAtRevision(byte[] key, long rev) throws KeyNotFoundException { final ImmudbProto.KeyRequest req = ImmudbProto.KeyRequest.newBuilder() .setKey(Utils.toByteString(key)) @@ -495,6 +664,10 @@ public synchronized Entry getAtRevision(byte[] key, long rev) throws KeyNotFound } } + /** + * @param keys the lists of keys to look for + * @return retrieves multiple entries in a single call + */ public synchronized List getAll(List keys) { final List keysBS = new ArrayList<>(keys.size()); @@ -514,18 +687,46 @@ public synchronized List getAll(List keys) { return result; } + /** + * @param key the keys to look for + * @return the latest entry associated to the provided key. Equivalent to + * {@link #get(String) get} but with additional + * server-provided proof validation. + */ public Entry verifiedGet(String key) throws KeyNotFoundException, VerificationException { return verifiedGetAtTx(key, 0); } + /** + * @param key the keys to look for + * @return the latest entry associated to the provided key. Equivalent to + * {@link #get(byte[]) get} but with additional + * server-provided proof validation. + */ public Entry verifiedGet(byte[] key) throws KeyNotFoundException, VerificationException { return verifiedGetAtTx(key, 0); } + /** + * @param key the key to look for + * @param tx the transaction at which the associated entry is expected to be + * @return the entry associated to the provided key and transaction. Equivalent + * to + * {@link #getAtTx(String, long) getAtTx} but with additional + * server-provided proof validation. + */ public Entry verifiedGetAtTx(String key, long tx) throws KeyNotFoundException, VerificationException { return verifiedGetAtTx(Utils.toByteArray(key), tx); } + /** + * @param key the key to look for + * @param tx the transaction at which the associated entry is expected to be + * @return the entry associated to the provided key and transaction. Equivalent + * to + * {@link #getAtTx(byte[], long) getAtTx} but with additional + * server-provided proof validation. + */ public synchronized Entry verifiedGetAtTx(byte[] key, long tx) throws KeyNotFoundException, VerificationException { final ImmuState state = state(); @@ -537,10 +738,38 @@ public synchronized Entry verifiedGetAtTx(byte[] key, long tx) throws KeyNotFoun return verifiedGet(keyReq, state); } + /** + * This method can be used to avoid additional latency while the server + * waits for the indexer to finish indexing but still guarantees that + * specific portion of the database history has already been indexed. + * + * @param key the key to look for + * @param tx the lowest transaction from which the associated entry should be + * retrieved + * @return the latest indexed entry associated the to provided key. Ensuring the + * indexing has already be completed up to the specified transaction. + * Equivalent to + * {@link #getSinceTx(String, long) getSinceTx} but with additional + * server-provided proof validation. + */ public Entry verifiedGetSinceTx(String key, long tx) throws KeyNotFoundException, VerificationException { return verifiedGetSinceTx(Utils.toByteArray(key), tx); } + /** + * This method can be used to avoid additional latency while the server + * waits for the indexer to finish indexing but still guarantees that + * specific portion of the database history has already been indexed. + * + * @param key the key to look for + * @param tx the lowest transaction from which the associated entry should be + * retrieved + * @return the latest indexed entry associated the to provided key. Ensuring the + * indexing has already be completed up to the specified transaction. + * Equivalent to + * {@link #getSinceTx(byte[], long) getSinceTx} but with additional + * server-provided proof validation. + */ public synchronized Entry verifiedGetSinceTx(byte[] key, long tx) throws KeyNotFoundException, VerificationException { @@ -554,10 +783,26 @@ public synchronized Entry verifiedGetSinceTx(byte[] key, long tx) return verifiedGet(keyReq, state); } + /** + * @param key the key to look for + * @param rev the specific revision + * @return the specific revision for given key. Equivalent to + * {@link #getAtRevision(String, long) getAtRevision} but with + * additional + * server-provided proof validation. + */ public Entry verifiedGetAtRevision(String key, long rev) throws KeyNotFoundException, VerificationException { return verifiedGetAtRevision(Utils.toByteArray(key), rev); } + /** + * @param key the key to look for + * @param rev the specific revision + * @return the specific revision for given key. Equivalent to + * {@link #getAtRevision(byte[], long) getAtRevision} but with + * additional + * server-provided proof validation. + */ public synchronized Entry verifiedGetAtRevision(byte[] key, long rev) throws KeyNotFoundException, VerificationException { @@ -671,10 +916,20 @@ private Entry verifiedGet(ImmudbProto.KeyRequest keyReq, ImmuState state) // ========== DELETE ========== // + /** + * Performs a logical deletion for key + * + * @param key the key to delete + */ public TxHeader delete(String key) throws KeyNotFoundException { return delete(Utils.toByteArray(key)); } + /** + * Performs a logical deletion for key + * + * @param key the key to delete + */ public synchronized TxHeader delete(byte[] key) throws KeyNotFoundException { try { final ImmudbProto.DeleteKeysRequest req = ImmudbProto.DeleteKeysRequest.newBuilder() @@ -695,10 +950,26 @@ public synchronized TxHeader delete(byte[] key) throws KeyNotFoundException { // ========== HISTORY ========== // + /** + * @param key the key to look for + * @param offset the number of entries to be skipped + * @param desc the order in which entries are returned + * @param limit the maximum number of entries to be returned + * @return the list of entries associated to the provided key + * @throws KeyNotFoundException if the key is not found + */ public List historyAll(String key, long offset, boolean desc, int limit) throws KeyNotFoundException { return historyAll(Utils.toByteArray(key), offset, desc, limit); } + /** + * @param key the key to look for + * @param offset the number of entries to be skipped + * @param desc the order in which entries are returned + * @param limit the maximum number of entries to be returned + * @return the list of entries associated to the provided key + * @throws KeyNotFoundException if the key is not found + */ public synchronized List historyAll(byte[] key, long offset, boolean desc, int limit) throws KeyNotFoundException { try { @@ -723,30 +994,75 @@ public synchronized List historyAll(byte[] key, long offset, boolean desc // ========== SCAN ========== // + /** + * @param prefix the prefix used to filter entries + * @return the list of entries with a maching prefix + */ public List scanAll(String prefix) { return scanAll(Utils.toByteArray(prefix)); } + /** + * @param prefix the prefix used to filter entries + * @return the list of entries with a maching prefix + */ public List scanAll(byte[] prefix) { return scanAll(prefix, false, 0); } + /** + * @param prefix the prefix used to filter entries + * @param desc the order in which entries are returned + * @param limit the maximum number of entries to be returned + * @return the list of entries with a maching prefix + */ public List scanAll(String prefix, boolean desc, long limit) { return scanAll(Utils.toByteArray(prefix), null, desc, limit); } + /** + * @param prefix the prefix used to filter entries + * @param desc the order in which entries are returned + * @param limit the maximum number of entries to be returned + * @return the list of entries with a maching prefix + */ public List scanAll(byte[] prefix, boolean desc, long limit) { return scanAll(prefix, null, desc, limit); } + /** + * @param prefix the prefix used to filter entries + * @param seekKey the initial key from which the scan begins + * @param desc the order in which entries are returned + * @param limit the maximum number of entries to be returned + * @return the list of entries with a maching prefix + */ public List scanAll(byte[] prefix, byte[] seekKey, boolean desc, long limit) { return scanAll(prefix, seekKey, null, desc, limit); } + /** + * @param prefix the prefix used to filter entries + * @param seekKey the initial key from which the scan begins + * @param endKey the final key at which the scan ends + * @param desc the order in which entries are returned + * @param limit the maximum number of entries to be returned + * @return the list of entries with a maching prefix + */ public List scanAll(byte[] prefix, byte[] seekKey, byte[] endKey, boolean desc, long limit) { - return scanAll(prefix, seekKey, endKey, false, false, desc, limit); + return scanAll(prefix, seekKey, endKey, true, true, desc, limit); } + /** + * @param prefix the prefix used to filter entries + * @param seekKey the initial key from which the scan begins + * @param endKey the final key at which the scan ends + * @param inclusiveSeek used to include/exclude the seekKey from the result + * @param inclusiveEnd used to include/exclude the endKey from the result + * @param desc the order in which entries are returned + * @param limit the maximum number of entries to be returned + * @return the list of entries with a maching prefix + */ public synchronized List scanAll(byte[] prefix, byte[] seekKey, byte[] endKey, boolean inclusiveSeek, boolean inclusiveEnd, boolean desc, long limit) { @@ -768,27 +1084,39 @@ public synchronized List scanAll(byte[] prefix, byte[] seekKey, byte[] en // ========== SET ========== // - public TxHeader set(String key, byte[] value) throws CorruptedDataException { + /** + * Commits a change of a value for a single key. + * + * @param key the key to set + * @param value the value to set + */ + public TxHeader set(String key, byte[] value) { return set(Utils.toByteArray(key), value); } - public synchronized TxHeader set(byte[] key, byte[] value) throws CorruptedDataException { + /** + * Commits a change of a value for a single key. + * + * @param key the key to set + * @param value the value to set + */ + public synchronized TxHeader set(byte[] key, byte[] value) { final ImmudbProto.KeyValue kv = ImmudbProto.KeyValue.newBuilder() .setKey(Utils.toByteString(key)) .setValue(Utils.toByteString(value)) .build(); final ImmudbProto.SetRequest req = ImmudbProto.SetRequest.newBuilder().addKVs(kv).build(); - final ImmudbProto.TxHeader txHdr = blockingStub.set(req); - - if (txHdr.getNentries() != 1) { - throw new CorruptedDataException(); - } - return TxHeader.valueOf(txHdr); + return TxHeader.valueOf(blockingStub.set(req)); } - public synchronized TxHeader setAll(List kvList) throws CorruptedDataException { + /** + * Commits multiple entries in a single transaction. + * + * @param kvList the list of key-value pairs to set + */ + public synchronized TxHeader setAll(List kvList) { final ImmudbProto.SetRequest.Builder reqBuilder = ImmudbProto.SetRequest.newBuilder(); for (KVPair kv : kvList) { @@ -800,29 +1128,28 @@ public synchronized TxHeader setAll(List kvList) throws CorruptedDataExc reqBuilder.addKVs(kvBuilder.build()); } - final ImmudbProto.TxHeader txHdr = blockingStub.set(reqBuilder.build()); - - if (txHdr.getNentries() != kvList.size()) { - throw new CorruptedDataException(); - } - - return TxHeader.valueOf(txHdr); + return TxHeader.valueOf(blockingStub.set(reqBuilder.build())); } - public TxHeader setReference(String key, String referencedKey) throws CorruptedDataException { + /** + * + * @param key + * @param referencedKey + * @return + */ + public TxHeader setReference(String key, String referencedKey) { return setReference(Utils.toByteArray(key), Utils.toByteArray(referencedKey)); } - public TxHeader setReference(byte[] key, byte[] referencedKey) throws CorruptedDataException { + public TxHeader setReference(byte[] key, byte[] referencedKey) { return setReference(key, referencedKey, 0); } - public TxHeader setReference(String key, String referencedKey, long atTx) throws CorruptedDataException { + public TxHeader setReference(String key, String referencedKey, long atTx) { return setReference(Utils.toByteArray(key), Utils.toByteArray(referencedKey), atTx); } - public synchronized TxHeader setReference(byte[] key, byte[] referencedKey, long atTx) - throws CorruptedDataException { + public synchronized TxHeader setReference(byte[] key, byte[] referencedKey, long atTx) { final ImmudbProto.ReferenceRequest req = ImmudbProto.ReferenceRequest.newBuilder() .setKey(Utils.toByteString(key)) .setReferencedKey(Utils.toByteString(referencedKey)) @@ -830,13 +1157,7 @@ public synchronized TxHeader setReference(byte[] key, byte[] referencedKey, long .setBoundRef(atTx > 0) .build(); - final ImmudbProto.TxHeader txHdr = blockingStub.setReference(req); - - if (txHdr.getNentries() != 1) { - throw new CorruptedDataException(); - } - - return TxHeader.valueOf(txHdr); + return TxHeader.valueOf(blockingStub.setReference(req)); } public TxHeader verifiedSet(String key, byte[] value) throws VerificationException { @@ -991,29 +1312,24 @@ private ImmuState verifyDualProof(ImmudbProto.VerifiableTx vtx, Tx tx, ImmuState // ========== Z ========== // - public TxHeader zAdd(String set, String key, double score) throws CorruptedDataException { + public TxHeader zAdd(String set, String key, double score) { return zAdd(Utils.toByteArray(set), Utils.toByteArray(key), score); } - public TxHeader zAdd(byte[] set, byte[] key, double score) throws CorruptedDataException { + public TxHeader zAdd(byte[] set, byte[] key, double score) { return zAdd(set, key, 0, score); } - public synchronized TxHeader zAdd(byte[] set, byte[] key, long atTx, double score) throws CorruptedDataException { - final ImmudbProto.TxHeader txHdr = blockingStub.zAdd( - ImmudbProto.ZAddRequest.newBuilder() - .setSet(Utils.toByteString(set)) - .setKey(Utils.toByteString(key)) - .setAtTx(atTx) - .setScore(score) - .setBoundRef(atTx > 0) - .build()); - - if (txHdr.getNentries() != 1) { - throw new CorruptedDataException(); - } + public synchronized TxHeader zAdd(byte[] set, byte[] key, long atTx, double score) { + ImmudbProto.ZAddRequest req = ImmudbProto.ZAddRequest.newBuilder() + .setSet(Utils.toByteString(set)) + .setKey(Utils.toByteString(key)) + .setAtTx(atTx) + .setScore(score) + .setBoundRef(atTx > 0) + .build(); - return TxHeader.valueOf(txHdr); + return TxHeader.valueOf(blockingStub.zAdd(req)); } public TxHeader verifiedZAdd(String set, String key, double score) throws VerificationException { @@ -1095,11 +1411,11 @@ public List zScanAll(String set) { } public List zScanAll(String set, boolean reverse, long limit) { - return pzScanAll(Utils.toByteArray(set), null, null, null, null, 0, false, reverse, limit); + return pzScanAll(Utils.toByteArray(set), null, null, null, null, 0, true, reverse, limit); } public List zScanAll(byte[] set, double minScore, double maxScore, boolean reverse, long limit) { - return pzScanAll(set, minScore, maxScore, null, null, 0, false, false, 0); + return pzScanAll(set, minScore, maxScore, null, null, 0, true, false, 0); } public List zScanAll(byte[] set, double minScore, double maxScore, double seekScore, byte[] seekKey, @@ -1377,12 +1693,12 @@ public ZEntry next() { // ========== STREAM SET ========== // - public TxHeader streamSet(String key, byte[] value) throws InterruptedException, CorruptedDataException { + public TxHeader streamSet(String key, byte[] value) throws InterruptedException { return streamSet(Utils.toByteArray(key), value); } public synchronized TxHeader streamSet(byte[] key, byte[] value) - throws InterruptedException, CorruptedDataException { + throws InterruptedException { final LatchHolder latchHolder = new LatchHolder<>(); final StreamObserver streamObserver = nonBlockingStub.streamSet(txHeaderStreamObserver(latchHolder)); @@ -1391,16 +1707,10 @@ public synchronized TxHeader streamSet(byte[] key, byte[] value) streamObserver.onCompleted(); - final ImmudbProto.TxHeader txHdr = latchHolder.awaitValue(); - - if (txHdr.getNentries() != 1) { - throw new CorruptedDataException(); - } - - return TxHeader.valueOf(txHdr); + return TxHeader.valueOf(latchHolder.awaitValue()); } - public synchronized TxHeader streamSetAll(List kvList) throws InterruptedException, CorruptedDataException { + public synchronized TxHeader streamSetAll(List kvList) throws InterruptedException { final LatchHolder latchHolder = new LatchHolder<>(); final StreamObserver streamObserver = nonBlockingStub.streamSet(txHeaderStreamObserver(latchHolder)); @@ -1411,13 +1721,7 @@ public synchronized TxHeader streamSetAll(List kvList) throws Interrupte streamObserver.onCompleted(); - final ImmudbProto.TxHeader txHdr = latchHolder.awaitValue(); - - if (txHdr.getNentries() != kvList.size()) { - throw new CorruptedDataException(); - } - - return TxHeader.valueOf(txHdr); + return TxHeader.valueOf(latchHolder.awaitValue()); } // @@ -1470,7 +1774,7 @@ public Iterator scan(byte[] prefix, byte[] seekKey, boolean desc, long li } public Iterator scan(byte[] prefix, byte[] seekKey, byte[] endKey, boolean desc, long limit) { - return scan(prefix, seekKey, endKey, false, false, desc, limit); + return scan(prefix, seekKey, endKey, true, true, desc, limit); } public synchronized Iterator scan(byte[] prefix, byte[] seekKey, byte[] endKey, boolean inclusiveSeek, @@ -1501,11 +1805,11 @@ public Iterator zScan(String set) { } public Iterator zScan(String set, boolean reverse, long limit) { - return pzScan(Utils.toByteArray(set), null, null, null, null, 0, false, reverse, limit); + return pzScan(Utils.toByteArray(set), null, null, null, null, 0, true, reverse, limit); } public Iterator zScan(byte[] set, double minScore, double maxScore, boolean reverse, long limit) { - return pzScan(set, minScore, maxScore, null, null, 0, false, false, 0); + return pzScan(set, minScore, maxScore, null, null, 0, true, false, 0); } public Iterator zScan(byte[] set, double minScore, double maxScore, double seekScore, byte[] seekKey, diff --git a/src/test/java/io/codenotary/immudb4j/BasicImmuClientTest.java b/src/test/java/io/codenotary/immudb4j/BasicImmuClientTest.java index 2b45252..4b4d373 100644 --- a/src/test/java/io/codenotary/immudb4j/BasicImmuClientTest.java +++ b/src/test/java/io/codenotary/immudb4j/BasicImmuClientTest.java @@ -16,7 +16,6 @@ package io.codenotary.immudb4j; import com.google.common.base.Charsets; -import io.codenotary.immudb4j.exceptions.CorruptedDataException; import io.codenotary.immudb4j.exceptions.KeyNotFoundException; import io.codenotary.immudb4j.exceptions.VerificationException; import io.grpc.StatusRuntimeException; @@ -30,7 +29,7 @@ public class BasicImmuClientTest extends ImmuClientIntegrationTest { @Test(testName = "set, get") - public void t1() throws VerificationException, CorruptedDataException, InterruptedException { + public void t1() throws VerificationException, InterruptedException { immuClient.openSession("defaultdb", "immudb", "immudb"); byte[] v0 = new byte[] { 0, 1, 2, 3 }; @@ -130,12 +129,8 @@ public void t2() { kvListBuilder.add(keys.get(i), values.get(i)); } - try { - immuClient.setAll(kvListBuilder.entries()); - } catch (CorruptedDataException e) { - Assert.fail("Failed at setAll.", e); - } - + immuClient.setAll(kvListBuilder.entries()); + List getAllResult = immuClient.getAll(keys); Assert.assertNotNull(getAllResult); diff --git a/src/test/java/io/codenotary/immudb4j/ExceptionsTest.java b/src/test/java/io/codenotary/immudb4j/ExceptionsTest.java index b135895..b288fe3 100644 --- a/src/test/java/io/codenotary/immudb4j/ExceptionsTest.java +++ b/src/test/java/io/codenotary/immudb4j/ExceptionsTest.java @@ -1,6 +1,5 @@ package io.codenotary.immudb4j; -import io.codenotary.immudb4j.exceptions.CorruptedDataException; import io.codenotary.immudb4j.exceptions.VerificationException; import org.testng.Assert; import org.testng.annotations.Test; @@ -9,12 +8,6 @@ public class ExceptionsTest { @Test public void t1() { - CorruptedDataException cdex = new CorruptedDataException(); - Assert.assertNull(cdex.getMessage()); - } - - @Test - public void t2() { String errorMsg = "data is corrupted"; VerificationException vex = new VerificationException(errorMsg); Assert.assertEquals(errorMsg, vex.getMessage()); diff --git a/src/test/java/io/codenotary/immudb4j/HistoryTest.java b/src/test/java/io/codenotary/immudb4j/HistoryTest.java index b210cf4..2230a47 100644 --- a/src/test/java/io/codenotary/immudb4j/HistoryTest.java +++ b/src/test/java/io/codenotary/immudb4j/HistoryTest.java @@ -15,7 +15,6 @@ */ package io.codenotary.immudb4j; -import io.codenotary.immudb4j.exceptions.CorruptedDataException; import io.codenotary.immudb4j.exceptions.KeyNotFoundException; import org.testng.Assert; import org.testng.annotations.Test; @@ -31,19 +30,15 @@ public class HistoryTest extends ImmuClientIntegrationTest { public void t1() { immuClient.openSession("defaultdb", "immudb", "immudb"); - byte[] value1 = {0, 1, 2, 3}; - byte[] value2 = {4, 5, 6, 7}; - byte[] value3 = {8, 9, 10, 11}; + byte[] value1 = { 0, 1, 2, 3 }; + byte[] value2 = { 4, 5, 6, 7 }; + byte[] value3 = { 8, 9, 10, 11 }; - try { - immuClient.set("history1", value1); - immuClient.set("history1", value2); - immuClient.set("history2", value1); - immuClient.set("history2", value2); - immuClient.set("history2", value3); - } catch (CorruptedDataException e) { - Assert.fail("Failed at set.", e); - } + immuClient.set("history1", value1); + immuClient.set("history1", value2); + immuClient.set("history2", value1); + immuClient.set("history2", value2); + immuClient.set("history2", value3); List historyResponse1 = immuClient.historyAll("history1", 0, false, 2); @@ -93,11 +88,11 @@ public void t1() { } catch (KeyNotFoundException e) { // exception is expected here } - + Iterator entriesIt2 = immuClient.history("nonExisting", 0, false, 0); - + Assert.assertFalse(entriesIt2.hasNext()); - + immuClient.closeSession(); } diff --git a/src/test/java/io/codenotary/immudb4j/ListDatabasesTest.java b/src/test/java/io/codenotary/immudb4j/ListDatabasesTest.java index 8a6bf72..7d7147a 100644 --- a/src/test/java/io/codenotary/immudb4j/ListDatabasesTest.java +++ b/src/test/java/io/codenotary/immudb4j/ListDatabasesTest.java @@ -30,11 +30,11 @@ public void t1() { public void t2() { immuClient.openSession("defaultdb", "immudb", "immudb"); - List databases = immuClient.databases(); + List databases = immuClient.databases(); if (databases.size() > 0) { System.out.print(">>> The databases are"); - for (String db : databases) { - System.out.printf(" '%s'", db); + for (Database db : databases) { + System.out.printf(" '%s'(loaded: %b)", db.getName(), db.isLoaded()); } } else { System.out.print(">>> There are no databases."); diff --git a/src/test/java/io/codenotary/immudb4j/MultidatabaseTest.java b/src/test/java/io/codenotary/immudb4j/MultidatabaseTest.java index 8b9f1ef..af216cd 100644 --- a/src/test/java/io/codenotary/immudb4j/MultidatabaseTest.java +++ b/src/test/java/io/codenotary/immudb4j/MultidatabaseTest.java @@ -15,7 +15,6 @@ */ package io.codenotary.immudb4j; -import io.codenotary.immudb4j.exceptions.CorruptedDataException; import io.codenotary.immudb4j.exceptions.VerificationException; import io.grpc.StatusRuntimeException; @@ -58,22 +57,16 @@ public void t5() throws VerificationException { immuClient.openSession("db1", "immudb", "immudb"); byte[] v0 = new byte[] { 0, 1, 2, 3 }; - try { - immuClient.set("k0", v0); - } catch (CorruptedDataException e) { - Assert.fail("Failed at set.", e); - } + + immuClient.set("k0", v0); immuClient.closeSession(); immuClient.openSession("db2", "immudb", "immudb"); byte[] v1 = new byte[] { 3, 2, 1, 0 }; - try { - immuClient.set("k1", v1); - } catch (CorruptedDataException e) { - Assert.fail("Failed at set.", e); - } + + immuClient.set("k1", v1); immuClient.closeSession(); @@ -97,12 +90,12 @@ public void t5() throws VerificationException { Entry ventry2 = immuClient.verifiedGet("k1"); Assert.assertEquals(ventry2.getValue(), v1); - List dbs = immuClient.databases(); + List dbs = immuClient.databases(); Assert.assertNotNull(dbs); Assert.assertEquals(3, dbs.size(), String.format("Expected 3, but got %d dbs: %s", dbs.size(), dbs)); - Assert.assertTrue(dbs.contains("defaultdb")); - Assert.assertTrue(dbs.contains("db1")); - Assert.assertTrue(dbs.contains("db2")); + Assert.assertEquals(dbs.get(0).getName(), "defaultdb"); + Assert.assertEquals(dbs.get(1).getName(), "db1"); + Assert.assertEquals(dbs.get(2).getName(), "db2"); immuClient.closeSession(); } @@ -117,15 +110,13 @@ public void t6() { immuClient.deleteDatabase("manageddb"); - /* try { immuClient.loadDatabase("manageddb"); Assert.fail("exception expected"); } catch (StatusRuntimeException e) { Assert.assertTrue(e.getMessage().contains("database does not exist")); } - */ - + immuClient.closeSession(); } } diff --git a/src/test/java/io/codenotary/immudb4j/ReferenceTest.java b/src/test/java/io/codenotary/immudb4j/ReferenceTest.java index cd9b0b7..2b93411 100644 --- a/src/test/java/io/codenotary/immudb4j/ReferenceTest.java +++ b/src/test/java/io/codenotary/immudb4j/ReferenceTest.java @@ -15,7 +15,6 @@ */ package io.codenotary.immudb4j; -import io.codenotary.immudb4j.exceptions.CorruptedDataException; import org.testng.Assert; import org.testng.annotations.Test; @@ -30,30 +29,15 @@ public void t1() { byte[] key = "testRef".getBytes(StandardCharsets.UTF_8); byte[] val = "abc".getBytes(StandardCharsets.UTF_8); - TxHeader setTxHdr = null; - try { - setTxHdr = immuClient.set(key, val); - } catch (CorruptedDataException e) { - Assert.fail("Failed at set.", e); - } + TxHeader setTxHdr = immuClient.set(key, val); byte[] ref1Key = "ref1_to_testRef".getBytes(StandardCharsets.UTF_8); byte[] ref2Key = "ref2_to_testRef".getBytes(StandardCharsets.UTF_8); - TxHeader ref1TxHdr = null; - try { - ref1TxHdr = immuClient.setReference(ref1Key, key); - } catch (CorruptedDataException e) { - Assert.fail("Failed at setReference", e); - } + TxHeader ref1TxHdr = immuClient.setReference(ref1Key, key); Assert.assertNotNull(ref1TxHdr); - TxHeader ref2TxHdr = null; - try { - ref2TxHdr = immuClient.setReference(ref2Key, key, setTxHdr.getId()); - } catch (CorruptedDataException e) { - Assert.fail("Failed at setReferenceAt.", e); - } + TxHeader ref2TxHdr = immuClient.setReference(ref2Key, key, setTxHdr.getId()); Assert.assertNotNull(ref2TxHdr); immuClient.closeSession(); diff --git a/src/test/java/io/codenotary/immudb4j/SQLTransactionsTest.java b/src/test/java/io/codenotary/immudb4j/SQLTransactionsTest.java index c5b4701..3381481 100644 --- a/src/test/java/io/codenotary/immudb4j/SQLTransactionsTest.java +++ b/src/test/java/io/codenotary/immudb4j/SQLTransactionsTest.java @@ -15,7 +15,6 @@ */ package io.codenotary.immudb4j; -import io.codenotary.immudb4j.exceptions.CorruptedDataException; import io.codenotary.immudb4j.exceptions.VerificationException; import io.codenotary.immudb4j.sql.SQLException; import io.codenotary.immudb4j.sql.SQLQueryResult; @@ -27,7 +26,7 @@ public class SQLTransactionsTest extends ImmuClientIntegrationTest { @Test(testName = "simple sql transaction") - public void t1() throws VerificationException, CorruptedDataException, InterruptedException, SQLException { + public void t1() throws VerificationException, InterruptedException, SQLException { immuClient.openSession("defaultdb", "immudb", "immudb"); immuClient.beginTransaction(); @@ -36,7 +35,7 @@ public void t1() throws VerificationException, CorruptedDataException, Interrupt "CREATE TABLE IF NOT EXISTS mytable(id INTEGER, title VARCHAR[256], active BOOLEAN, PRIMARY KEY id)"); final int rows = 10; - + for (int i = 0; i < rows; i++) { immuClient.sqlExec("UPSERT INTO mytable(id, title, active) VALUES (?, ?, ?)", new SQLValue(i), diff --git a/src/test/java/io/codenotary/immudb4j/ScanTest.java b/src/test/java/io/codenotary/immudb4j/ScanTest.java index 3fe658a..6070620 100644 --- a/src/test/java/io/codenotary/immudb4j/ScanTest.java +++ b/src/test/java/io/codenotary/immudb4j/ScanTest.java @@ -15,7 +15,6 @@ */ package io.codenotary.immudb4j; -import io.codenotary.immudb4j.exceptions.CorruptedDataException; import org.testng.Assert; import org.testng.annotations.Test; @@ -32,29 +31,17 @@ public void t1() { byte[] value1 = { 0, 1, 2, 3 }; byte[] value2 = { 4, 5, 6, 7 }; - try { - immuClient.set("scan1", value1); - immuClient.set("scan2", value2); - } catch (CorruptedDataException e) { - Assert.fail("Failed at set.", e); - } + immuClient.set("scan1", value1); + immuClient.set("scan2", value2); - try { - immuClient.set("zadd1", value1); - immuClient.set("zadd2", value2); - } catch (CorruptedDataException e) { - Assert.fail("Failed at set.", e); - } + immuClient.set("zadd1", value1); + immuClient.set("zadd2", value2); - try { - immuClient.zAdd("set1", "zadd1", 1); - immuClient.zAdd("set1", "zadd2", 2); + immuClient.zAdd("set1", "zadd1", 1); + immuClient.zAdd("set1", "zadd2", 2); - immuClient.zAdd("set2", "zadd1", 2); - immuClient.zAdd("set2", "zadd2", 1); - } catch (CorruptedDataException e) { - Assert.fail("Failed to zAdd", e); - } + immuClient.zAdd("set2", "zadd1", 2); + immuClient.zAdd("set2", "zadd2", 1); List scanResult = immuClient.scanAll("scan"); System.out.println(scanResult.size()); diff --git a/src/test/java/io/codenotary/immudb4j/SetAllAndGetAllTest.java b/src/test/java/io/codenotary/immudb4j/SetAllAndGetAllTest.java index 4c879b9..011612a 100644 --- a/src/test/java/io/codenotary/immudb4j/SetAllAndGetAllTest.java +++ b/src/test/java/io/codenotary/immudb4j/SetAllAndGetAllTest.java @@ -15,7 +15,6 @@ */ package io.codenotary.immudb4j; -import io.codenotary.immudb4j.exceptions.CorruptedDataException; import org.testng.Assert; import org.testng.annotations.Test; @@ -41,12 +40,8 @@ public void t1() { .add(new KVPair(key3, val3)) .entries(); - try { - TxHeader txHdr = immuClient.setAll(kvs); - Assert.assertNotNull(txHdr); - } catch (CorruptedDataException e) { - Assert.fail("Failed at SetAll.", e); - } + TxHeader txHdr = immuClient.setAll(kvs); + Assert.assertNotNull(txHdr); List keys = Arrays.asList(key1, key2, key3); List got = immuClient.getAll(keys); @@ -54,7 +49,8 @@ public void t1() { Assert.assertEquals(kvs.size(), got.size()); for (int i = 0; i < kvs.size(); i++) { - Assert.assertEquals(got.get(i).getValue(), kvs.get(i).getValue(), String.format("Expected: %s got: %s", kvs.get(i), got.get(i))); + Assert.assertEquals(got.get(i).getValue(), kvs.get(i).getValue(), + String.format("Expected: %s got: %s", kvs.get(i), got.get(i))); } immuClient.closeSession(); diff --git a/src/test/java/io/codenotary/immudb4j/SetAndGetTest.java b/src/test/java/io/codenotary/immudb4j/SetAndGetTest.java index 4f711cd..78169f8 100644 --- a/src/test/java/io/codenotary/immudb4j/SetAndGetTest.java +++ b/src/test/java/io/codenotary/immudb4j/SetAndGetTest.java @@ -15,7 +15,6 @@ */ package io.codenotary.immudb4j; -import io.codenotary.immudb4j.exceptions.CorruptedDataException; import io.codenotary.immudb4j.exceptions.KeyNotFoundException; import org.testng.Assert; import org.testng.annotations.Test; @@ -27,14 +26,9 @@ public void t1() { immuClient.openSession("defaultdb", "immudb", "immudb"); String key = "key1"; - byte[] val = new byte[]{1, 2, 3, 4, 5}; + byte[] val = new byte[] { 1, 2, 3, 4, 5 }; - TxHeader txHdr = null; - try { - txHdr = immuClient.set(key, val); - } catch (CorruptedDataException e) { - Assert.fail("Failed at set.", e); - } + TxHeader txHdr = immuClient.set(key, val); Assert.assertNotNull(txHdr); Entry entry1 = immuClient.get(key); diff --git a/src/test/java/io/codenotary/immudb4j/StreamSetAllTest.java b/src/test/java/io/codenotary/immudb4j/StreamSetAllTest.java index a08fe4a..ce2df58 100644 --- a/src/test/java/io/codenotary/immudb4j/StreamSetAllTest.java +++ b/src/test/java/io/codenotary/immudb4j/StreamSetAllTest.java @@ -15,7 +15,6 @@ */ package io.codenotary.immudb4j; -import io.codenotary.immudb4j.exceptions.CorruptedDataException; import org.testng.Assert; import org.testng.annotations.Test; @@ -44,7 +43,7 @@ public void t1() { try { TxHeader txHdr = immuClient.streamSetAll(kvs); Assert.assertNotNull(txHdr); - } catch (InterruptedException|CorruptedDataException e) { + } catch (InterruptedException e) { Assert.fail("Failed at SetAll.", e); } @@ -54,7 +53,8 @@ public void t1() { Assert.assertEquals(kvs.size(), got.size()); for (int i = 0; i < kvs.size(); i++) { - Assert.assertEquals(got.get(i).getValue(), kvs.get(i).getValue(), String.format("Expected: %s got: %s", kvs.get(i), got.get(i))); + Assert.assertEquals(got.get(i).getValue(), kvs.get(i).getValue(), + String.format("Expected: %s got: %s", kvs.get(i), got.get(i))); } immuClient.closeSession(); diff --git a/src/test/java/io/codenotary/immudb4j/StreamSetAndGetTest.java b/src/test/java/io/codenotary/immudb4j/StreamSetAndGetTest.java index c5ce019..0d2538c 100644 --- a/src/test/java/io/codenotary/immudb4j/StreamSetAndGetTest.java +++ b/src/test/java/io/codenotary/immudb4j/StreamSetAndGetTest.java @@ -15,7 +15,6 @@ */ package io.codenotary.immudb4j; -import io.codenotary.immudb4j.exceptions.CorruptedDataException; import io.codenotary.immudb4j.exceptions.KeyNotFoundException; import org.testng.Assert; import org.testng.annotations.Test; @@ -27,12 +26,12 @@ public void t1() { immuClient.openSession("defaultdb", "immudb", "immudb"); String key = "key1"; - byte[] val = new byte[]{1, 2, 3, 4, 5}; + byte[] val = new byte[] { 1, 2, 3, 4, 5 }; TxHeader txHdr = null; try { txHdr = immuClient.streamSet(key, val); - } catch (CorruptedDataException|InterruptedException e) { + } catch (InterruptedException e) { Assert.fail("Failed at set.", e); } Assert.assertNotNull(txHdr); diff --git a/src/test/java/io/codenotary/immudb4j/TxTest.java b/src/test/java/io/codenotary/immudb4j/TxTest.java index 8951510..8cc8d06 100644 --- a/src/test/java/io/codenotary/immudb4j/TxTest.java +++ b/src/test/java/io/codenotary/immudb4j/TxTest.java @@ -15,7 +15,6 @@ */ package io.codenotary.immudb4j; -import io.codenotary.immudb4j.exceptions.CorruptedDataException; import io.codenotary.immudb4j.exceptions.TxNotFoundException; import io.codenotary.immudb4j.exceptions.VerificationException; import org.testng.Assert; @@ -28,7 +27,7 @@ public class TxTest extends ImmuClientIntegrationTest { @Test(testName = "verifiedSet, txById, verifiedTxById") - public void t1() throws NoSuchAlgorithmException, VerificationException{ + public void t1() throws NoSuchAlgorithmException, VerificationException { immuClient.openSession("defaultdb", "immudb", "immudb"); String key = "test-txid"; @@ -54,13 +53,13 @@ public void t1() throws NoSuchAlgorithmException, VerificationException{ Assert.assertEquals(txHdr.getId(), tx.getHeader().getId()); try { - immuClient.txById(txHdr.getId()+1); + immuClient.txById(txHdr.getId() + 1); Assert.fail("Failed at txById."); } catch (TxNotFoundException _) { } try { - immuClient.verifiedTxById(txHdr.getId()+1); + immuClient.verifiedTxById(txHdr.getId() + 1); Assert.fail("Failed at verifiedTxById."); } catch (TxNotFoundException _) { } @@ -77,15 +76,12 @@ public void t2() { byte[] val2 = "immuRocks! Again!".getBytes(StandardCharsets.UTF_8); long initialTxId = 1; - try { - TxHeader txHdr = immuClient.set(key, val1); - Assert.assertNotNull(txHdr); - initialTxId = txHdr.getId(); - txHdr = immuClient.set(key, val2); - Assert.assertNotNull(txHdr); - } catch (CorruptedDataException e) { - Assert.fail("Failed at set.", e); - } + + TxHeader txHdr = immuClient.set(key, val1); + Assert.assertNotNull(txHdr); + initialTxId = txHdr.getId(); + txHdr = immuClient.set(key, val2); + Assert.assertNotNull(txHdr); List txs = immuClient.txScanAll(initialTxId, false, 1); Assert.assertNotNull(txs); diff --git a/src/test/java/io/codenotary/immudb4j/VerifiedSetAndGetTest.java b/src/test/java/io/codenotary/immudb4j/VerifiedSetAndGetTest.java index a74b9dc..017f8e0 100644 --- a/src/test/java/io/codenotary/immudb4j/VerifiedSetAndGetTest.java +++ b/src/test/java/io/codenotary/immudb4j/VerifiedSetAndGetTest.java @@ -15,7 +15,6 @@ */ package io.codenotary.immudb4j; -import io.codenotary.immudb4j.exceptions.CorruptedDataException; import io.codenotary.immudb4j.exceptions.VerificationException; import org.testng.Assert; import org.testng.annotations.Test; @@ -32,11 +31,7 @@ public void t1() { String key = "vsg"; byte[] val = "test-set-vget".getBytes(StandardCharsets.UTF_8); - try { - immuClient.set(key, val); - } catch (CorruptedDataException e) { - Assert.fail("Failed at set.", e); - } + immuClient.set(key, val); Entry vEntry = null; try { @@ -103,7 +98,7 @@ public void t3() throws InterruptedException, IllegalStateException, IOException immuClient.verifiedSet("key1", "val1".getBytes()); immuClient.closeSession(); - + immuClient.shutdown(); FileImmuStateHolder stateHolder = FileImmuStateHolder.newBuilder() diff --git a/src/test/java/io/codenotary/immudb4j/ZAddTest.java b/src/test/java/io/codenotary/immudb4j/ZAddTest.java index c00cba1..6d7d938 100644 --- a/src/test/java/io/codenotary/immudb4j/ZAddTest.java +++ b/src/test/java/io/codenotary/immudb4j/ZAddTest.java @@ -15,7 +15,6 @@ */ package io.codenotary.immudb4j; -import io.codenotary.immudb4j.exceptions.CorruptedDataException; import io.codenotary.immudb4j.exceptions.VerificationException; import org.testng.Assert; import org.testng.annotations.Test; @@ -34,23 +33,14 @@ public void t1() { String key2 = "key2"; byte[] val2 = "val234".getBytes(StandardCharsets.UTF_8); - try { - immuClient.set(key1, val1); - immuClient.set(key2, val2); - } catch (CorruptedDataException e) { - Assert.fail("Failed at set.", e); - } + immuClient.set(key1, val1); + immuClient.set(key2, val2); - TxHeader txHdr = null; - try { - txHdr = immuClient.zAdd(set, key1, 10); - Assert.assertNotNull(txHdr); + TxHeader txHdr = immuClient.zAdd(set, key1, 10); + Assert.assertNotNull(txHdr); - txHdr = immuClient.zAdd(set, key2, 4); - Assert.assertNotNull(txHdr); - } catch (CorruptedDataException e) { - Assert.fail("Failed at zAdd.", e); - } + txHdr = immuClient.zAdd(set, key2, 4); + Assert.assertNotNull(txHdr); try { txHdr = immuClient.verifiedZAdd(set, key2, 8);