|
| 1 | +/* |
| 2 | + * Copyright 2021 TiKV Project Authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + */ |
| 17 | + |
| 18 | +package org.tikv.raw; |
| 19 | + |
| 20 | +import static org.junit.Assert.assertTrue; |
| 21 | + |
| 22 | +import org.junit.Test; |
| 23 | +import org.tikv.BaseRawKVTest; |
| 24 | +import org.tikv.common.TiConfiguration; |
| 25 | +import org.tikv.common.TiSession; |
| 26 | +import org.tikv.kvproto.Errorpb; |
| 27 | + |
| 28 | +public class WarmupTest extends BaseRawKVTest { |
| 29 | + |
| 30 | + @Test |
| 31 | + public void testErrorpbToStringEnableWarmup() throws Exception { |
| 32 | + TiConfiguration conf = createTiConfiguration(); |
| 33 | + TiSession session = TiSession.create(conf); |
| 34 | + |
| 35 | + long start = System.currentTimeMillis(); |
| 36 | + Errorpb.Error.newBuilder() |
| 37 | + .setNotLeader(Errorpb.NotLeader.newBuilder().build()) |
| 38 | + .build() |
| 39 | + .toString(); |
| 40 | + long end = System.currentTimeMillis(); |
| 41 | + assertTrue(end - start < 10); |
| 42 | + session.close(); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void testErrorpbToStringDisableWarmup() throws Exception { |
| 47 | + TiConfiguration conf = createTiConfiguration(); |
| 48 | + conf.setWarmUpEnable(false); |
| 49 | + TiSession session = TiSession.create(conf); |
| 50 | + |
| 51 | + long start = System.currentTimeMillis(); |
| 52 | + Errorpb.Error.newBuilder() |
| 53 | + .setNotLeader(Errorpb.NotLeader.newBuilder().build()) |
| 54 | + .build() |
| 55 | + .toString(); |
| 56 | + long end = System.currentTimeMillis(); |
| 57 | + assertTrue(end - start > 10); |
| 58 | + session.close(); |
| 59 | + } |
| 60 | +} |
0 commit comments