|
| 1 | +package com.datastax.driver.core; |
| 2 | + |
| 3 | +import static org.testng.Assert.assertEquals; |
| 4 | + |
| 5 | +import com.datastax.driver.core.utils.Bytes; |
| 6 | +import io.netty.buffer.ByteBuf; |
| 7 | +import io.netty.buffer.ByteBufAllocator; |
| 8 | +import org.testng.annotations.DataProvider; |
| 9 | +import org.testng.annotations.Test; |
| 10 | + |
| 11 | +public class RequestsTest { |
| 12 | + |
| 13 | + public static class ExecuteTest { |
| 14 | + |
| 15 | + @Test(groups = "unit", dataProvider = "shouldProperlyEncodeMessages") |
| 16 | + void should_properly_encode_messages( |
| 17 | + MD5Digest resultMetadataId, |
| 18 | + ProtocolVersion protocolVersion, |
| 19 | + ProtocolFeatureStore protocolFeatureStore, |
| 20 | + int expectedSize) { |
| 21 | + // given |
| 22 | + ByteBuf destination = ByteBufAllocator.DEFAULT.buffer(); |
| 23 | + Requests.Execute request = |
| 24 | + new Requests.Execute( |
| 25 | + MD5Digest.wrap(Bytes.fromHexString("0xcafebabe").array()), |
| 26 | + resultMetadataId, |
| 27 | + Requests.QueryProtocolOptions.DEFAULT, |
| 28 | + false); |
| 29 | + |
| 30 | + // when |
| 31 | + int size = Requests.Execute.coder.encodedSize(request, protocolVersion, protocolFeatureStore); |
| 32 | + Requests.Execute.coder.encode(request, destination, protocolVersion, protocolFeatureStore); |
| 33 | + |
| 34 | + // then |
| 35 | + assertEquals(size, expectedSize); |
| 36 | + assertEquals(destination.writerIndex(), expectedSize); |
| 37 | + } |
| 38 | + |
| 39 | + @DataProvider |
| 40 | + Object[][] shouldProperlyEncodeMessages() { |
| 41 | + return new Object[][] { |
| 42 | + { |
| 43 | + MD5Digest.wrap(Bytes.fromHexString("0xdeadbeef").array()), |
| 44 | + ProtocolVersion.V4, |
| 45 | + new ProtocolFeatureStore(null, null, null, false), |
| 46 | + 9 |
| 47 | + }, |
| 48 | + { |
| 49 | + MD5Digest.wrap(Bytes.fromHexString("0xdeadbeef").array()), |
| 50 | + ProtocolVersion.V4, |
| 51 | + new ProtocolFeatureStore(null, null, null, true), |
| 52 | + 15 |
| 53 | + }, |
| 54 | + {null, ProtocolVersion.V4, new ProtocolFeatureStore(null, null, null, true), 11}, |
| 55 | + { |
| 56 | + MD5Digest.wrap(Bytes.fromHexString("0xdeadbeef").array()), |
| 57 | + ProtocolVersion.V5, |
| 58 | + new ProtocolFeatureStore(null, null, null, false), |
| 59 | + 18 |
| 60 | + }, |
| 61 | + {null, ProtocolVersion.V5, new ProtocolFeatureStore(null, null, null, false), 14}, |
| 62 | + }; |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments