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));
}