Search in sources :

Example 41 with ThrowingRunnable

use of org.junit.function.ThrowingRunnable in project aerospike-client-java by aerospike.

the class TestFilterExp method putExcept.

@Test
public void putExcept() {
    WritePolicy policy = new WritePolicy();
    policy.filterExp = Exp.build(Exp.eq(Exp.intBin(binA), Exp.val(1)));
    policy.failOnFilteredOut = true;
    Bin bin = new Bin(binA, 3);
    client.put(policy, keyA, bin);
    AerospikeException ae = assertThrows(AerospikeException.class, new ThrowingRunnable() {

        public void run() {
            client.put(policy, keyB, bin);
        }
    });
    assertEquals(ResultCode.FILTERED_OUT, ae.getResultCode());
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Bin(com.aerospike.client.Bin) WritePolicy(com.aerospike.client.policy.WritePolicy) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 42 with ThrowingRunnable

use of org.junit.function.ThrowingRunnable in project aerospike-client-java by aerospike.

the class TestExpOperation method expWritePolicyError.

@Test
public void expWritePolicyError() {
    Expression wexp = Exp.build(Exp.add(Exp.intBin(binA), Exp.val(4)));
    AerospikeException ae = assertThrows(AerospikeException.class, new ThrowingRunnable() {

        public void run() {
            client.operate(null, keyA, ExpOperation.write(binC, wexp, ExpWriteFlags.UPDATE_ONLY));
        }
    });
    assertEquals(ResultCode.BIN_NOT_FOUND, ae.getResultCode());
    Record record = client.operate(null, keyA, ExpOperation.write(binC, wexp, ExpWriteFlags.UPDATE_ONLY | ExpWriteFlags.POLICY_NO_FAIL));
    assertRecordFound(keyA, record);
    // System.out.println(record);
    record = client.operate(null, keyA, ExpOperation.write(binC, wexp, ExpWriteFlags.CREATE_ONLY));
    assertRecordFound(keyA, record);
    // System.out.println(record);
    ae = assertThrows(AerospikeException.class, new ThrowingRunnable() {

        public void run() {
            client.operate(null, keyA, ExpOperation.write(binC, wexp, ExpWriteFlags.CREATE_ONLY));
        }
    });
    assertEquals(ResultCode.BIN_EXISTS_ERROR, ae.getResultCode());
    record = client.operate(null, keyA, ExpOperation.write(binC, wexp, ExpWriteFlags.CREATE_ONLY | ExpWriteFlags.POLICY_NO_FAIL));
    assertRecordFound(keyA, record);
    Expression dexp = Exp.build(Exp.nil());
    ae = assertThrows(AerospikeException.class, new ThrowingRunnable() {

        public void run() {
            client.operate(null, keyA, ExpOperation.write(binC, dexp, ExpWriteFlags.DEFAULT));
        }
    });
    assertEquals(ResultCode.OP_NOT_APPLICABLE, ae.getResultCode());
    record = client.operate(null, keyA, ExpOperation.write(binC, dexp, ExpWriteFlags.POLICY_NO_FAIL));
    assertRecordFound(keyA, record);
    record = client.operate(null, keyA, ExpOperation.write(binC, dexp, ExpWriteFlags.ALLOW_DELETE));
    assertRecordFound(keyA, record);
    record = client.operate(null, keyA, ExpOperation.write(binC, wexp, ExpWriteFlags.CREATE_ONLY));
    assertRecordFound(keyA, record);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Expression(com.aerospike.client.exp.Expression) Record(com.aerospike.client.Record) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 43 with ThrowingRunnable

use of org.junit.function.ThrowingRunnable in project aerospike-client-java by aerospike.

the class TestExpOperation method expReadEvalError.

@Test
public void expReadEvalError() {
    Expression exp = Exp.build(Exp.add(Exp.intBin(binA), Exp.val(4)));
    Record record = client.operate(null, keyA, ExpOperation.read(expVar, exp, ExpReadFlags.DEFAULT));
    assertRecordFound(keyA, record);
    // System.out.println(record);
    AerospikeException ae = assertThrows(AerospikeException.class, new ThrowingRunnable() {

        public void run() {
            // Bin AString doesn't exist on keyB.
            client.operate(null, keyB, ExpOperation.read(expVar, exp, ExpReadFlags.DEFAULT));
        }
    });
    assertEquals(ResultCode.OP_NOT_APPLICABLE, ae.getResultCode());
    // Try NO_FAIL.
    record = client.operate(null, keyB, ExpOperation.read(expVar, exp, ExpReadFlags.EVAL_NO_FAIL));
    assertRecordFound(keyB, record);
// System.out.println(record);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Expression(com.aerospike.client.exp.Expression) Record(com.aerospike.client.Record) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 44 with ThrowingRunnable

use of org.junit.function.ThrowingRunnable in project aerospike-client-java by aerospike.

the class TestExpOperation method expWriteEvalError.

@Test
public void expWriteEvalError() {
    Expression wexp = Exp.build(Exp.add(Exp.intBin(binA), Exp.val(4)));
    Expression rexp = Exp.build(Exp.intBin(binC));
    Record record = client.operate(null, keyA, ExpOperation.write(binC, wexp, ExpReadFlags.DEFAULT), ExpOperation.read(expVar, rexp, ExpReadFlags.DEFAULT));
    assertRecordFound(keyA, record);
    // System.out.println(record);
    AerospikeException ae = assertThrows(AerospikeException.class, new ThrowingRunnable() {

        public void run() {
            client.operate(null, keyB, ExpOperation.write(binC, wexp, ExpWriteFlags.DEFAULT), ExpOperation.read(expVar, rexp, ExpReadFlags.DEFAULT));
        }
    });
    assertEquals(ResultCode.OP_NOT_APPLICABLE, ae.getResultCode());
    // Add NO_FAIL.
    record = client.operate(null, keyB, ExpOperation.write(binC, wexp, ExpWriteFlags.EVAL_NO_FAIL), ExpOperation.read(expVar, rexp, ExpReadFlags.EVAL_NO_FAIL));
    assertRecordFound(keyB, record);
// System.out.println(record);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Expression(com.aerospike.client.exp.Expression) Record(com.aerospike.client.Record) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 45 with ThrowingRunnable

use of org.junit.function.ThrowingRunnable in project aerospike-client-java by aerospike.

the class TestFilterExp method filterToFloat.

@Test
public void filterToFloat() {
    Policy policy = new Policy();
    policy.filterExp = Exp.build(Exp.eq(Exp.toFloat(Exp.intBin(binA)), Exp.val(2.0)));
    policy.failOnFilteredOut = true;
    AerospikeException ae = assertThrows(AerospikeException.class, new ThrowingRunnable() {

        public void run() {
            client.get(policy, keyA);
        }
    });
    assertEquals(ResultCode.FILTERED_OUT, ae.getResultCode());
    Record r = client.get(policy, keyB);
    assertBinEqual(keyA, r, binA, 2);
}
Also used : Policy(com.aerospike.client.policy.Policy) BatchPolicy(com.aerospike.client.policy.BatchPolicy) WritePolicy(com.aerospike.client.policy.WritePolicy) AerospikeException(com.aerospike.client.AerospikeException) Record(com.aerospike.client.Record) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Aggregations

ThrowingRunnable (org.junit.function.ThrowingRunnable)49 Test (org.junit.Test)48 AerospikeException (com.aerospike.client.AerospikeException)41 WritePolicy (com.aerospike.client.policy.WritePolicy)34 Record (com.aerospike.client.Record)32 BatchPolicy (com.aerospike.client.policy.BatchPolicy)28 Policy (com.aerospike.client.policy.Policy)28 Expression (com.aerospike.client.exp.Expression)5 Bin (com.aerospike.client.Bin)3 Key (com.aerospike.client.Key)2 Options (com.github.jknack.handlebars.Options)2 RandomTestUtils.randomString (uk.nhs.digital.test.util.RandomTestUtils.randomString)2 Drawable (android.graphics.drawable.Drawable)1 Handler (android.os.Handler)1 Version (com.aerospike.client.util.Version)1 Matchers.anyDrawable (com.bumptech.glide.test.Matchers.anyDrawable)1 Migration (com.google.copybara.config.Migration)1 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 MarkdownConversionException (uk.nhs.digital.common.components.apispecification.commonmark.MarkdownConversionException)1