|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package org.apache.hadoop.hdfs.server.federation.router; |
| 19 | + |
| 20 | +import org.apache.hadoop.conf.Configuration; |
| 21 | +import org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcRequestHeaderProto; |
| 22 | +import org.junit.jupiter.api.Assertions; |
| 23 | +import org.junit.jupiter.api.Test; |
| 24 | + |
| 25 | + |
| 26 | +public class TestPoolAlignmentContext { |
| 27 | + @Test |
| 28 | + public void testNamenodeRequestsOnlyUsePoolLocalStateID() { |
| 29 | + RouterStateIdContext routerStateIdContext = new RouterStateIdContext(new Configuration()); |
| 30 | + String namespaceId = "namespace1"; |
| 31 | + routerStateIdContext.getNamespaceStateId(namespaceId).accumulate(20L); |
| 32 | + PoolAlignmentContext poolContext1 = new PoolAlignmentContext(routerStateIdContext, namespaceId); |
| 33 | + PoolAlignmentContext poolContext2 = new PoolAlignmentContext(routerStateIdContext, namespaceId); |
| 34 | + |
| 35 | + assertRequestHeaderStateId(poolContext1, Long.MIN_VALUE); |
| 36 | + assertRequestHeaderStateId(poolContext2, Long.MIN_VALUE); |
| 37 | + Assertions.assertEquals(20L, poolContext1.getLastSeenStateId()); |
| 38 | + Assertions.assertEquals(20L, poolContext2.getLastSeenStateId()); |
| 39 | + |
| 40 | + poolContext1.advanceClientStateId(30L); |
| 41 | + assertRequestHeaderStateId(poolContext1, 30L); |
| 42 | + assertRequestHeaderStateId(poolContext2, Long.MIN_VALUE); |
| 43 | + Assertions.assertEquals(20L, poolContext1.getLastSeenStateId()); |
| 44 | + Assertions.assertEquals(20L, poolContext2.getLastSeenStateId()); |
| 45 | + } |
| 46 | + |
| 47 | + private void assertRequestHeaderStateId(PoolAlignmentContext poolAlignmentContext, |
| 48 | + Long expectedValue) { |
| 49 | + RpcRequestHeaderProto.Builder builder = RpcRequestHeaderProto.newBuilder(); |
| 50 | + poolAlignmentContext.updateRequestState(builder); |
| 51 | + Assertions.assertEquals(expectedValue, builder.getStateId()); |
| 52 | + } |
| 53 | +} |
0 commit comments