Search in sources :

Example 11 with TiDAGRequest

use of com.pingcap.tikv.meta.TiDAGRequest in project tispark by pingcap.

the class DAGIteratorTest method staleEpochTest.

@Test
public void staleEpochTest() {
    Metapb.Store store = Metapb.Store.newBuilder().setAddress(LOCAL_ADDR + ":" + port).setId(1).setState(Metapb.StoreState.Up).setVersion(Version.RESOLVE_LOCK_V4).build();
    TiTableInfo table = createTable();
    TiDAGRequest req = new TiDAGRequest(PushDownType.NORMAL);
    req.setTableInfo(table);
    req.addRequiredColumn(ColumnRef.create("c1", IntegerType.INT));
    req.addRequiredColumn(ColumnRef.create("c2", StringType.VARCHAR));
    req.setStartTs(new TiTimestamp(0, 1));
    List<KeyRange> keyRanges = ImmutableList.of(createByteStringRange(ByteString.copyFromUtf8("key1"), ByteString.copyFromUtf8("key4")));
    pdServer.addGetRegionResp(GrpcUtils.makeGetRegionResponse(pdServer.getClusterId(), region.getMeta()));
    pdServer.addGetStoreResp(GrpcUtils.makeGetStoreResponse(pdServer.getClusterId(), store));
    server.putError("key1", KVMockServer.STALE_EPOCH);
    CodecDataOutput cdo = new CodecDataOutput();
    IntegerCodec.writeLongFully(cdo, 666, false);
    BytesCodec.writeBytesFully(cdo, "value1".getBytes());
    server.put("key1", cdo.toByteString());
    List<RegionTask> tasks = ImmutableList.of(RegionTask.newInstance(region, store, keyRanges));
    CoprocessorIterator<Row> iter = CoprocessorIterator.getRowIterator(req, tasks, session);
    if (!iter.hasNext()) {
        assertEquals("iterator has next should be true", true, false);
    } else {
        Row r = iter.next();
        SchemaInfer infer = SchemaInfer.create(req);
        assertEquals(r.get(0, infer.getType(0)), 666L);
        assertEquals(r.get(1, infer.getType(1)), "value1");
    }
}
Also used : TiTimestamp(com.pingcap.tikv.meta.TiTimestamp) KeyRange(org.tikv.kvproto.Coprocessor.KeyRange) TiDAGRequest(com.pingcap.tikv.meta.TiDAGRequest) RegionTask(com.pingcap.tikv.util.RangeSplitter.RegionTask) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) CodecDataOutput(com.pingcap.tikv.codec.CodecDataOutput) Row(com.pingcap.tikv.row.Row) SchemaInfer(com.pingcap.tikv.operation.SchemaInfer) Metapb(org.tikv.kvproto.Metapb) MockServerTest(com.pingcap.tikv.MockServerTest) Test(org.junit.Test)

Aggregations

TiDAGRequest (com.pingcap.tikv.meta.TiDAGRequest)11 DataType (com.pingcap.tikv.types.DataType)5 Test (org.junit.Test)4 TiTableInfo (com.pingcap.tikv.meta.TiTableInfo)3 Row (com.pingcap.tikv.row.Row)3 ArrayList (java.util.ArrayList)3 TiChunk (com.pingcap.tikv.columnar.TiChunk)2 KeyRange (org.tikv.kvproto.Coprocessor.KeyRange)2 Context (com.alibaba.citrus.turbine.Context)1 Lists (com.pingcap.com.google.common.collect.Lists)1 Maps (com.pingcap.com.google.common.collect.Maps)1 MockServerTest (com.pingcap.tikv.MockServerTest)1 Snapshot (com.pingcap.tikv.Snapshot)1 TiConfiguration (com.pingcap.tikv.TiConfiguration)1 TiSession (com.pingcap.tikv.TiSession)1 Catalog (com.pingcap.tikv.catalog.Catalog)1 CodecDataInput (com.pingcap.tikv.codec.CodecDataInput)1 CodecDataOutput (com.pingcap.tikv.codec.CodecDataOutput)1 BatchedTiChunkColumnVector (com.pingcap.tikv.columnar.BatchedTiChunkColumnVector)1 TiChunkColumnVector (com.pingcap.tikv.columnar.TiChunkColumnVector)1