aderm commented on a change in pull request #4517: fix elasticsearch-5.x-plugin 
when use es6.x TransportClient error
URL: https://github.com/apache/skywalking/pull/4517#discussion_r398695604
 
 

 ##########
 File path: 
apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyExecuteMethodsInterceptorTest.java
 ##########
 @@ -0,0 +1,241 @@
+/*
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.skywalking.apm.plugin.elasticsearch.v6.interceptor;
+
+import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
+import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan;
+import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
+import org.apache.skywalking.apm.agent.core.context.util.TagValuePair;
+import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
+import org.apache.skywalking.apm.agent.test.helper.SpanHelper;
+import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule;
+import org.apache.skywalking.apm.agent.test.tools.SegmentStorage;
+import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
+import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
+import 
org.apache.skywalking.apm.plugin.elasticsearch.v6.TransportClientEnhanceInfo;
+import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
+import org.elasticsearch.action.delete.DeleteRequest;
+import org.elasticsearch.action.get.GetRequest;
+import org.elasticsearch.action.index.IndexRequest;
+import org.elasticsearch.action.search.SearchRequest;
+import org.elasticsearch.action.update.UpdateRequest;
+import org.elasticsearch.cluster.node.DiscoveryNode;
+import org.elasticsearch.common.transport.TransportAddress;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+
+import java.net.InetSocketAddress;
+import java.util.List;
+
+import static 
org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL;
+import static 
org.apache.skywalking.apm.network.trace.component.ComponentsDefine.TRANSPORT_CLIENT;
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+public class TransportActionNodeProxyExecuteMethodsInterceptorTest {
+
+    @SegmentStoragePoint
+    private SegmentStorage segmentStorage;
+
+    @Rule
+    public AgentServiceRule serviceRule = new AgentServiceRule();
+
+    @Mock
+    private EnhancedInstance enhancedInstance;
+
+    @Mock
+    private DiscoveryNode discoveryNode;
+
+//    @Mock
+//    private SearchRequest searchRequest;
+
+    @Mock
+    private GetRequest getRequest;
+
+    @Mock
+    private IndexRequest indexRequest;
+
+    @Mock
+    private UpdateRequest updateRequest;
+
+    @Mock
+    private DeleteRequest deleteRequest;
+
+    @Mock
+    private DeleteIndexRequest deleteIndexRequest;
+
+    @Mock
+    private TransportClientEnhanceInfo enhanceInfo;
+
+    private TransportActionNodeProxyExecuteMethodsInterceptor interceptor;
+
+    @Before
+    public void setUp() {
+
+        InetSocketAddress inetSocketAddress = new 
InetSocketAddress("122.122.122.122", 9300);
+        TransportAddress transportAddress = new 
TransportAddress(inetSocketAddress);
+        when(discoveryNode.getAddress()).thenReturn(transportAddress);
+
+        
when(enhanceInfo.transportAddresses()).thenReturn("122.122.122.122:9300");
+        when(enhanceInfo.getClusterName()).thenReturn("skywalking-es");
+        
when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(enhanceInfo);
+
+//        when(searchRequest.indices()).thenReturn(new String[]{"endpoint"});
+//        when(searchRequest.types()).thenReturn(new String[]{"searchType"});
+
+        when(getRequest.index()).thenReturn("endpoint");
+        when(getRequest.type()).thenReturn("getType");
+
+        when(indexRequest.index()).thenReturn("endpoint");
+        when(indexRequest.type()).thenReturn("indexType");
+
+        when(updateRequest.index()).thenReturn("endpoint");
+        when(updateRequest.type()).thenReturn("updateType");
+
+        when(deleteRequest.index()).thenReturn("endpoint");
+        when(deleteRequest.type()).thenReturn("deleteType");
+
+        when(deleteIndexRequest.indices()).thenReturn(new 
String[]{"endpoint"});
+
+        interceptor = new TransportActionNodeProxyExecuteMethodsInterceptor();
+    }
+
+    @Test
+    public void testConstruct() {
+
+        final EnhancedInstance objInst1 = new EnhancedInstance() {
+            private Object object = null;
+
+            @Override
+            public Object getSkyWalkingDynamicField() {
+                return object;
+            }
+
+            @Override
+            public void setSkyWalkingDynamicField(Object value) {
+                this.object = value;
+            }
+        };
+
+        final EnhancedInstance objInst2 = new EnhancedInstance() {
+            private Object object = null;
+
+            @Override
+            public Object getSkyWalkingDynamicField() {
+                return object;
+            }
+
+            @Override
+            public void setSkyWalkingDynamicField(Object value) {
+                this.object = value;
+            }
+        };
+
+        objInst1.setSkyWalkingDynamicField(123);
+        Object[] allArguments = new Object[]{null, null, objInst1};
+
+        interceptor.onConstruct(objInst2, allArguments);
+        assertThat(objInst1.getSkyWalkingDynamicField(), 
is(objInst2.getSkyWalkingDynamicField()));
+    }
+
+    @Test
+    public void testGetRequest() throws Throwable {
+
+        AbstractTracingSpan getSpan = getSpan();
+        assertGetSpan(getSpan, getRequest);
+    }
+
+    @Test
+    public void testIndexRequest() throws Throwable {
+
+        AbstractTracingSpan getSpan = getSpan();
+        assertGetSpan(getSpan, getRequest);
+    }
+
+    @Test
+    public void testUpdateRequest() throws Throwable {
+
+        AbstractTracingSpan getSpan = getSpan();
+        assertGetSpan(getSpan, getRequest);
+    }
+
+    @Test
+    public void testDeleteRequest() throws Throwable {
+
+        AbstractTracingSpan getSpan = getSpan();
+        assertGetSpan(getSpan, getRequest);
 
 Review comment:
   `getRequest ` maybe `deleteRequest`?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to