use of com.aerospike.client.operation.BitPolicy in project aerospike-client-java by aerospike.
the class TestOperateBit method operateBitResize.
@Test
public void operateBitResize() {
client.delete(null, key);
BitPolicy policy = new BitPolicy();
BitPolicy noFail = new BitPolicy(BitWriteFlags.NO_FAIL);
Record record = client.operate(null, key, BitOperation.resize(policy, binName, 20, BitResizeFlags.DEFAULT), BitOperation.get(binName, 19 * 8, 8), BitOperation.resize(noFail, binName, 10, BitResizeFlags.GROW_ONLY), BitOperation.get(binName, 19 * 8, 8), BitOperation.resize(policy, binName, 10, BitResizeFlags.SHRINK_ONLY), BitOperation.get(binName, 9 * 8, 8), BitOperation.resize(noFail, binName, 30, BitResizeFlags.SHRINK_ONLY), BitOperation.get(binName, 9 * 8, 8), BitOperation.resize(policy, binName, 19, BitResizeFlags.GROW_ONLY), BitOperation.get(binName, 18 * 8, 8), BitOperation.resize(noFail, binName, 0, BitResizeFlags.GROW_ONLY), BitOperation.resize(policy, binName, 0, BitResizeFlags.SHRINK_ONLY));
// System.out.println("Record: " + record);
List<?> result_list = record.getList(binName);
byte[] get0 = (byte[]) result_list.get(1);
byte[] get1 = (byte[]) result_list.get(3);
byte[] get2 = (byte[]) result_list.get(5);
byte[] get3 = (byte[]) result_list.get(7);
byte[] get4 = (byte[]) result_list.get(9);
assertArrayEquals(new byte[] { 0x00 }, get0);
assertArrayEquals(new byte[] { 0x00 }, get1);
assertArrayEquals(new byte[] { 0x00 }, get2);
assertArrayEquals(new byte[] { 0x00 }, get3);
assertArrayEquals(new byte[] { 0x00 }, get4);
}
use of com.aerospike.client.operation.BitPolicy in project aerospike-client-java by aerospike.
the class TestOperateBit method operateBitNullBlob.
@Test
public void operateBitNullBlob() {
BitPolicy policy = new BitPolicy();
byte[] initial = new byte[] {};
byte[] buf = new byte[] { (byte) 0x80 };
client.delete(null, key);
client.put(null, key, new Bin(binName, initial));
assertThrows(AerospikeException.class, 26, BitOperation.set(policy, binName, 0, 1, buf));
assertThrows(AerospikeException.class, 26, BitOperation.or(policy, binName, 0, 1, buf));
assertThrows(AerospikeException.class, 26, BitOperation.xor(policy, binName, 0, 1, buf));
assertThrows(AerospikeException.class, 26, BitOperation.and(policy, binName, 0, 1, buf));
assertThrows(AerospikeException.class, 26, BitOperation.not(policy, binName, 0, 1));
assertThrows(AerospikeException.class, 26, BitOperation.lshift(policy, binName, 0, 1, 1));
assertThrows(AerospikeException.class, 26, BitOperation.rshift(policy, binName, 0, 1, 1));
// OK for insert.
assertThrows(AerospikeException.class, 4, BitOperation.remove(policy, binName, 0, 1));
assertThrows(AerospikeException.class, 26, BitOperation.add(policy, binName, 0, 1, 1, false, BitOverflowAction.FAIL));
assertThrows(AerospikeException.class, 26, BitOperation.subtract(policy, binName, 0, 1, 1, false, BitOverflowAction.FAIL));
assertThrows(AerospikeException.class, 26, BitOperation.setInt(policy, binName, 0, 1, 1));
assertThrows(AerospikeException.class, 26, BitOperation.get(binName, 0, 1));
assertThrows(AerospikeException.class, 26, BitOperation.count(binName, 0, 1));
assertThrows(AerospikeException.class, 26, BitOperation.lscan(binName, 0, 1, true));
assertThrows(AerospikeException.class, 26, BitOperation.rscan(binName, 0, 1, true));
assertThrows(AerospikeException.class, 26, BitOperation.getInt(binName, 0, 1, false));
}
use of com.aerospike.client.operation.BitPolicy in project aerospike-client-java by aerospike.
the class TestOperateBit method operateBitRShift.
@Test
public void operateBitRShift() {
BitPolicy putMode = new BitPolicy();
assertBitModifyOperations(new byte[] { (byte) 0x80, 0x40, 0x01, 0x00, (byte) 0xFF, 0x01, 0x01, 0x18, (byte) 0x80 }, new byte[] { 0x40, 0x01, 0x00, (byte) 0x80, (byte) 0xF8, (byte) 0xE0, 0x21, 0x14, (byte) 0x80 }, BitOperation.rshift(putMode, binName, 0, 8, 1), BitOperation.rshift(putMode, binName, 9, 7, 6), BitOperation.rshift(putMode, binName, 23, 2, 1), BitOperation.rshift(putMode, binName, 37, 18, 3), BitOperation.rshift(putMode, binName, 60, 2, 1), BitOperation.rshift(putMode, binName, 68, 4, 7));
}
use of com.aerospike.client.operation.BitPolicy in project aerospike-client-java by aerospike.
the class TestOperateBit method operateBitLShift.
@Test
public void operateBitLShift() {
BitPolicy putMode = new BitPolicy();
assertBitModifyOperations(new byte[] { 0x01, 0x01, 0x00, (byte) 0x80, (byte) 0xFF, 0x01, 0x01, 0x18, 0x01 }, new byte[] { (byte) 0x02, 0x40, 0x01, 0x00, (byte) 0xF8, 0x08, 0x01, 0x28, 0x01 }, BitOperation.lshift(putMode, binName, 0, 8, 1), BitOperation.lshift(putMode, binName, 9, 7, 6), BitOperation.lshift(putMode, binName, 23, 2, 1), BitOperation.lshift(putMode, binName, 37, 18, 3), BitOperation.lshift(putMode, binName, 58, 2, 1), BitOperation.lshift(putMode, binName, 64, 4, 7));
assertBitModifyOperations(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, new byte[] { (byte) 0xF8, 0x00, 0x0F }, BitOperation.lshift(putMode, binName, 0, 20, 15));
}
use of com.aerospike.client.operation.BitPolicy in project aerospike-client-java by aerospike.
the class TestOperateBit method operateBitSub.
@Test
public void operateBitSub() {
BitPolicy putMode = new BitPolicy();
assertBitModifyOperations(new byte[] { 0x38, 0x1F, 0x00, (byte) 0xE8, 0x7F, (byte) 0x80, (byte) 0x80, (byte) 0x80, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03 }, new byte[] { 0x30, 0x1E, 0x00, (byte) 0xD0, 0x7E, 0x7F, 0x7F, 0x7F, 0x00, (byte) 0xF0, (byte) 0xF1, 0x00, 0x00, 0x00, 0x01, (byte) 0xFD, (byte) 0xFE, 0x00, (byte) 0xE0, (byte) 0xE1 }, BitOperation.subtract(putMode, binName, 0, 5, 0x01, false, BitOverflowAction.FAIL), BitOperation.subtract(putMode, binName, 9, 7, 0x01, false, BitOverflowAction.FAIL), BitOperation.subtract(putMode, binName, 23, 6, 0x03, false, BitOverflowAction.FAIL), BitOperation.subtract(putMode, binName, 32, 8, 0x01, false, BitOverflowAction.FAIL), BitOperation.subtract(putMode, binName, 40, 24, 0x10101, false, BitOverflowAction.FAIL), BitOperation.subtract(putMode, binName, 64, 20, 0x101, false, BitOverflowAction.FAIL), BitOperation.subtract(putMode, binName, 92, 20, 0x10101, false, BitOverflowAction.FAIL), BitOperation.subtract(putMode, binName, 113, 21, 0x101, false, BitOverflowAction.FAIL), BitOperation.subtract(putMode, binName, 136, 23, 0x11111, false, BitOverflowAction.FAIL));
byte[] initial = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
int i = 0;
assertBitModifyOperations(initial, new byte[] { (byte) 0xFF, (byte) 0xF6, 0x7F, 0x00, (byte) 0x80, 0x7F }, BitOperation.subtract(putMode, binName, 8 * i++, 8, 0x01, false, BitOverflowAction.WRAP), BitOperation.subtract(putMode, binName, 8 * i, 8, 0x80, true, BitOverflowAction.WRAP), BitOperation.subtract(putMode, binName, 8 * i++, 8, 0x8A, true, BitOverflowAction.WRAP), BitOperation.subtract(putMode, binName, 8 * i, 8, 0x7F, true, BitOverflowAction.WRAP), BitOperation.subtract(putMode, binName, 8 * i++, 8, 0x02, true, BitOverflowAction.WRAP), BitOperation.subtract(putMode, binName, 8 * i++, 8, 0xAA, false, BitOverflowAction.SATURATE), BitOperation.subtract(putMode, binName, 8 * i, 8, 0x77, true, BitOverflowAction.SATURATE), BitOperation.subtract(putMode, binName, 8 * i++, 8, 0x77, true, BitOverflowAction.SATURATE), BitOperation.subtract(putMode, binName, 8 * i, 8, 0x81, true, BitOverflowAction.SATURATE), BitOperation.subtract(putMode, binName, 8 * i++, 8, 0x8F, true, BitOverflowAction.SATURATE));
client.put(null, key, new Bin(binName, initial));
assertThrows(AerospikeException.class, 26, BitOperation.subtract(putMode, binName, 0, 8, 1, false, BitOverflowAction.FAIL));
assertThrows(AerospikeException.class, 26, BitOperation.subtract(putMode, binName, 0, 8, 0x7F, true, BitOverflowAction.FAIL), BitOperation.subtract(putMode, binName, 0, 8, 0x02, true, BitOverflowAction.FAIL));
assertThrows(AerospikeException.class, 26, BitOperation.subtract(putMode, binName, 0, 8, 0x81, true, BitOverflowAction.FAIL), BitOperation.subtract(putMode, binName, 0, 8, 0xFE, true, BitOverflowAction.FAIL));
}