|
26 | 26 | */ |
27 | 27 | package org.hbase.async; |
28 | 28 |
|
| 29 | +import static org.junit.Assert.assertArrayEquals; |
29 | 30 | import static org.junit.Assert.assertEquals; |
30 | 31 | import static org.junit.Assert.assertSame; |
31 | 32 | import static org.junit.Assert.assertTrue; |
|
40 | 41 | import java.util.Collections; |
41 | 42 | import java.util.List; |
42 | 43 |
|
| 44 | +import org.hbase.async.generated.ClientPB.MultiRequest; |
43 | 45 | import org.hbase.async.generated.ClientPB.MultiResponse; |
| 46 | +import org.hbase.async.generated.ClientPB.RegionAction; |
44 | 47 | import org.hbase.async.generated.ClientPB.RegionActionResult; |
45 | 48 | import org.hbase.async.generated.ClientPB.ResultOrException; |
46 | 49 | import org.hbase.async.generated.ClientPB.RegionActionResult.Builder; |
@@ -212,6 +215,48 @@ public void addErrors() throws Exception { |
212 | 215 | } |
213 | 216 |
|
214 | 217 | // NOTE: The following are tests for HBase 0.96 and up |
| 218 | + |
| 219 | + @Test |
| 220 | + public void serdesOrdering() throws Exception { |
| 221 | + PutRequest put1 = new PutRequest(TABLE, concat(KEY, new byte[] { 2 }), |
| 222 | + FAMILY, QUALIFIER, VALUE); |
| 223 | + put1.region = region; |
| 224 | + PutRequest put2 = new PutRequest(TABLE, KEY, FAMILY, "myqual".getBytes(), VALUE); |
| 225 | + put2.region = region; |
| 226 | + PutRequest put3 = new PutRequest(TABLE, concat(KEY, new byte[] { 2 }), |
| 227 | + FAMILY, "myqual".getBytes(), VALUE); |
| 228 | + put3.region = region2; |
| 229 | + PutRequest put4 = new PutRequest(TABLE, KEY, FAMILY, "myqual".getBytes(), VALUE); |
| 230 | + put4.region = region2; |
| 231 | + MultiAction multi = new MultiAction(); |
| 232 | + multi.add(put1); |
| 233 | + multi.add(put2); |
| 234 | + multi.add(put3); |
| 235 | + multi.add(put4); |
| 236 | + |
| 237 | + ChannelBuffer buffer = multi.serialize(RegionClient.SERVER_VERSION_095_OR_ABOVE); |
| 238 | + buffer.readerIndex(4 + 19 + MultiAction.MMULTI.length); |
| 239 | + HBaseRpc.readProtoBufVarint(buffer); |
| 240 | + byte[] bytes = new byte[buffer.writerIndex() - buffer.readerIndex()]; |
| 241 | + buffer.readBytes(bytes); |
| 242 | + MultiRequest parsed = MultiRequest.parseFrom(bytes); |
| 243 | + assertEquals(2, parsed.getRegionActionCount()); |
| 244 | + |
| 245 | + RegionAction actions = parsed.getRegionAction(0); |
| 246 | + assertEquals(2, actions.getActionCount()); |
| 247 | + assertArrayEquals(region.name(), actions.getRegion().getValue().toByteArray()); |
| 248 | + assertArrayEquals(KEY, actions.getAction(0).getMutation().getRow().toByteArray()); |
| 249 | + assertArrayEquals(concat(KEY, new byte[] { 2 }), |
| 250 | + actions.getAction(1).getMutation().getRow().toByteArray()); |
| 251 | + |
| 252 | + actions = parsed.getRegionAction(1); |
| 253 | + assertEquals(2, actions.getActionCount()); |
| 254 | + assertArrayEquals(region2.name(), actions.getRegion().getValue().toByteArray()); |
| 255 | + assertArrayEquals(KEY, actions.getAction(0).getMutation().getRow().toByteArray()); |
| 256 | + assertArrayEquals(concat(KEY, new byte[] { 2 }), |
| 257 | + actions.getAction(1).getMutation().getRow().toByteArray()); |
| 258 | + } |
| 259 | + |
215 | 260 | @Test |
216 | 261 | public void deserializePuts() throws Exception { |
217 | 262 | final List<ResultOrException> results = new ArrayList<ResultOrException>(2); |
@@ -870,7 +915,7 @@ public void deserializeMultiRegionOneFailed() throws Exception { |
870 | 915 | multi.add(put2); |
871 | 916 | multi.add(put3); |
872 | 917 | multi.add(put4); |
873 | | - Collections.sort(multi.batch(), MultiAction.SORT_BY_REGION); |
| 918 | + Collections.sort(multi.batch(), MultiAction.SORT_BY_REGION_AND_KEY); |
874 | 919 |
|
875 | 920 | final MultiAction.Response decoded = |
876 | 921 | (MultiAction.Response)multi.deserialize( |
@@ -916,7 +961,7 @@ public void deserializeMultiRegionTwoFailed() throws Exception { |
916 | 961 | multi.add(put2); |
917 | 962 | multi.add(put3); |
918 | 963 | multi.add(put4); |
919 | | - Collections.sort(multi.batch(), MultiAction.SORT_BY_REGION); |
| 964 | + Collections.sort(multi.batch(), MultiAction.SORT_BY_REGION_AND_KEY); |
920 | 965 |
|
921 | 966 | final MultiAction.Response decoded = |
922 | 967 | (MultiAction.Response)multi.deserialize( |
|
0 commit comments