use of com.aerospike.client.operation.BitPolicy in project aerospike-client-java by aerospike.
the class TestOperateBit method operateBitXor.
@Test
public void operateBitXor() {
byte[] bits1 = new byte[] { 0x11, 0x22, 0x33 };
BitPolicy putMode = new BitPolicy();
assertBitModifyOperations(new byte[] { (byte) 0x80, 0x40, 0x01, 0x00, 0x00, 0x01, 0x02, 0x03 }, new byte[] { (byte) 0x90, 0x48, 0x01, 0x20, 0x11, 0x10, 0x20, 0x30 }, BitOperation.xor(putMode, binName, 0, 5, bits1), BitOperation.xor(putMode, binName, 9, 7, bits1), BitOperation.xor(putMode, binName, 23, 6, bits1), BitOperation.xor(putMode, binName, 32, 8, bits1), BitOperation.xor(putMode, binName, 40, 24, bits1));
}
use of com.aerospike.client.operation.BitPolicy in project aerospike-client-java by aerospike.
the class TestOperateBit method operateBitBin.
@Test
public void operateBitBin() {
byte[] bit0 = new byte[] { (byte) 0x80 };
BitPolicy putMode = BitPolicy.Default;
BitPolicy updateMode = new BitPolicy(BitWriteFlags.UPDATE_ONLY);
assertBitModifyOperations(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }, new byte[] { 0x51, 0x02, 0x03, 0x04, 0x05, 0x06 }, BitOperation.set(putMode, binName, 1, 1, bit0), BitOperation.set(updateMode, binName, 3, 1, bit0), BitOperation.remove(updateMode, binName, 6, 2));
BitPolicy addMode = new BitPolicy(BitWriteFlags.CREATE_ONLY);
byte[] bytes1 = new byte[] { 0x0A };
assertBitModifyOperations(null, new byte[] { 0x00, 0x0A }, BitOperation.insert(addMode, binName, 1, bytes1));
assertThrows(AerospikeException.class, 17, BitOperation.set(putMode, "b", 1, 1, bit0));
assertThrows(AerospikeException.class, 4, BitOperation.set(addMode, binName, 1, 1, bit0));
}
use of com.aerospike.client.operation.BitPolicy in project aerospike-client-java by aerospike.
the class TestOperateBit method operateBitOr.
@Test
public void operateBitOr() {
byte[] bits1 = new byte[] { 0x11, 0x22, 0x33 };
BitPolicy putMode = new BitPolicy();
assertBitModifyOperations(new byte[] { (byte) 0x80, 0x40, 0x01, 0x00, 0x00, 0x01, 0x02, 0x03 }, new byte[] { (byte) 0x90, (byte) 0x48, 0x01, 0x20, 0x11, (byte) 0x11, (byte) 0x22, 0x33 }, BitOperation.or(putMode, binName, 0, 5, bits1), BitOperation.or(putMode, binName, 9, 7, bits1), BitOperation.or(putMode, binName, 23, 6, bits1), BitOperation.or(putMode, binName, 32, 8, bits1), BitOperation.or(putMode, binName, 40, 24, bits1));
}
use of com.aerospike.client.operation.BitPolicy in project aerospike-client-java by aerospike.
the class TestOperateBit method operateBitAdd.
@Test
public void operateBitAdd() {
BitPolicy putMode = new BitPolicy();
assertBitModifyOperations(new byte[] { 0x38, 0x1F, 0x00, (byte) 0xE8, 0x7F, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03 }, new byte[] { 0x40, 0x20, 0x01, (byte) 0xF0, (byte) 0x80, 0x7F, 0x7F, 0x7F, 0x02, 0x02, 0x01, 0x02, 0x02, 0x02, 0x03, 0x03, 0x06, 0x07, 0x07, 0x07 }, BitOperation.add(putMode, binName, 0, 5, 1, false, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 9, 7, 1, false, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 23, 6, 0x21, false, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 32, 8, 1, false, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 40, 24, 0x7F7F7F, false, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 64, 20, 0x01010, false, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 92, 20, 0x10101, false, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 113, 22, 0x8082, false, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 136, 23, 0x20202, false, BitOverflowAction.FAIL));
byte[] initial = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
int i = 0;
assertBitModifyOperations(initial, new byte[] { (byte) 0xFE, (byte) 0xFE, 0x7F, (byte) 0xFF, 0x7F, (byte) 0x80 }, BitOperation.add(putMode, binName, 8 * i, 8, 0xFF, false, BitOverflowAction.WRAP), BitOperation.add(putMode, binName, 8 * i++, 8, 0xFF, false, BitOverflowAction.WRAP), BitOperation.add(putMode, binName, 8 * i, 8, 0x7F, true, BitOverflowAction.WRAP), BitOperation.add(putMode, binName, 8 * i++, 8, 0x7F, true, BitOverflowAction.WRAP), BitOperation.add(putMode, binName, 8 * i, 8, 0x80, true, BitOverflowAction.WRAP), BitOperation.add(putMode, binName, 8 * i++, 8, 0xFF, true, BitOverflowAction.WRAP), BitOperation.add(putMode, binName, 8 * i, 8, 0x80, false, BitOverflowAction.SATURATE), BitOperation.add(putMode, binName, 8 * i++, 8, 0x80, false, BitOverflowAction.SATURATE), BitOperation.add(putMode, binName, 8 * i, 8, 0x77, true, BitOverflowAction.SATURATE), BitOperation.add(putMode, binName, 8 * i++, 8, 0x77, true, BitOverflowAction.SATURATE), BitOperation.add(putMode, binName, 8 * i, 8, 0x8F, true, BitOverflowAction.SATURATE), BitOperation.add(putMode, binName, 8 * i++, 8, 0x8F, true, BitOverflowAction.SATURATE));
client.put(null, key, new Bin(binName, initial));
assertThrows(AerospikeException.class, 26, BitOperation.add(putMode, binName, 0, 8, 0xFF, false, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 0, 8, 0xFF, false, BitOverflowAction.FAIL));
assertThrows(AerospikeException.class, 26, BitOperation.add(putMode, binName, 0, 8, 0x7F, true, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 0, 8, 0x02, true, BitOverflowAction.FAIL));
assertThrows(AerospikeException.class, 26, BitOperation.add(putMode, binName, 0, 8, 0x81, true, BitOverflowAction.FAIL), BitOperation.add(putMode, binName, 0, 8, 0xFE, true, BitOverflowAction.FAIL));
}
use of com.aerospike.client.operation.BitPolicy in project aerospike-client-java by aerospike.
the class TestOperateBit method operateBitInsertEx.
@Test
public void operateBitInsertEx() {
BitPolicy policy = new BitPolicy();
int bin_sz = 15;
for (int set_sz = 1; set_sz <= 10; set_sz++) {
byte[] set_data = new byte[set_sz];
for (int offset = 0; offset <= bin_sz; offset++) {
assertBitModifyInsert(bin_sz, offset * 8, set_sz * 8, set_data, BitOperation.insert(policy, binName, offset, set_data));
}
}
}