| /** |
| * Licensed to the Apache Software Foundation (ASF) under one or more |
| * contributor license agreements. See the NOTICE file distributed with this |
| * work for additional information regarding copyright ownership. The ASF |
| * licenses this file to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * <p> |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * <p> |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| * License for the specific language governing permissions and limitations under |
| * the License. |
| */ |
| |
| package org.apache.hadoop.ozone.container.common; |
| |
| import org.apache.hadoop.conf.Configuration; |
| import org.apache.hadoop.io.retry.RetryPolicies; |
| import org.apache.hadoop.ipc.ProtobufRpcEngine; |
| import org.apache.hadoop.ipc.RPC; |
| import org.apache.hadoop.net.NetUtils; |
| import org.apache.hadoop.ozone.container.common.statemachine |
| .EndpointStateMachine; |
| import org.apache.hadoop.ozone.protocolPB |
| .StorageContainerDatanodeProtocolClientSideTranslatorPB; |
| import org.apache.hadoop.ozone.protocolPB.StorageContainerDatanodeProtocolPB; |
| import org.apache.hadoop.security.UserGroupInformation; |
| |
| import java.net.InetSocketAddress; |
| |
| /** |
| * Helper utility to test containers. |
| */ |
| public final class ContainerTestUtils { |
| |
| private ContainerTestUtils() { |
| } |
| |
| /** |
| * Creates an Endpoint class for testing purpose. |
| * |
| * @param conf - Conf |
| * @param address - InetAddres |
| * @param rpcTimeout - rpcTimeOut |
| * @return EndPoint |
| * @throws Exception |
| */ |
| public static EndpointStateMachine createEndpoint(Configuration conf, |
| InetSocketAddress address, int rpcTimeout) throws Exception { |
| RPC.setProtocolEngine(conf, StorageContainerDatanodeProtocolPB.class, |
| ProtobufRpcEngine.class); |
| long version = |
| RPC.getProtocolVersion(StorageContainerDatanodeProtocolPB.class); |
| |
| StorageContainerDatanodeProtocolPB rpcProxy = RPC.getProtocolProxy( |
| StorageContainerDatanodeProtocolPB.class, version, |
| address, UserGroupInformation.getCurrentUser(), conf, |
| NetUtils.getDefaultSocketFactory(conf), rpcTimeout, |
| RetryPolicies.TRY_ONCE_THEN_FAIL).getProxy(); |
| |
| StorageContainerDatanodeProtocolClientSideTranslatorPB rpcClient = |
| new StorageContainerDatanodeProtocolClientSideTranslatorPB(rpcProxy); |
| return new EndpointStateMachine(address, rpcClient, conf); |
| } |
| } |