Skip to content

Commit

Permalink
[#noissue] Fix proxy-user plugin test
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehong-kim committed Apr 13, 2023
1 parent 3ebfca5 commit 046d24f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@
public class UserRequestParser implements ProxyRequestParser {
private List<String> headerNameList = Collections.emptyList();

@Override
public String getHttpHeaderName() {
return "";
}

@Override
public List<String> getHttpHeaderNameList() {
return this.headerNameList;
Expand All @@ -52,12 +47,6 @@ public void init(ProfilerConfig profilerConfig) {
this.headerNameList = profilerConfig.readList(UserRequestConstants.USER_PROXY_HEADER_NAME_LIST);
}

@Override
@Deprecated
public ProxyRequestHeader parse(String value) {
return parseHeader("UNKNOWN", value);
}

@Override
public ProxyRequestHeader parseHeader(String name, String value) {
final ProxyRequestHeaderBuilder header = new ProxyRequestHeaderBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package com.navercorp.pinpoint.agent.plugin.proxy.user;

import com.navercorp.pinpoint.profiler.context.recorder.proxy.ProxyRequestHeader;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.assertThat;

public class UserRequestParserTest {

Expand All @@ -28,53 +28,50 @@ public void parse() {
UserRequestParser parser = new UserRequestParser();
String value = "t=1625212448369 D=123";
ProxyRequestHeader proxyHttpHeader = parser.parseHeader("HEADER_NAME", value);
assertTrue(proxyHttpHeader.isValid());
assertEquals(1625212448369L, proxyHttpHeader.getReceivedTimeMillis());
assertEquals(123L, proxyHttpHeader.getDurationTimeMicroseconds());
assertEquals("HEADER_NAME", proxyHttpHeader.getApp());
assertEquals(-1, proxyHttpHeader.getIdlePercent());
assertEquals(-1, proxyHttpHeader.getBusyPercent());
assertThat(proxyHttpHeader.isValid()).isTrue();
assertThat(1625212448369L).isEqualTo(proxyHttpHeader.getReceivedTimeMillis());
assertThat(123L).isEqualTo(proxyHttpHeader.getDurationTimeMicroseconds());
assertThat("HEADER_NAME").isEqualTo(proxyHttpHeader.getApp());
assertThat(-1).isEqualTo(proxyHttpHeader.getIdlePercent());
assertThat(-1).isEqualTo(proxyHttpHeader.getBusyPercent());
}

@Test
public void parseOnlyReceivedTime() {
UserRequestParser parser = new UserRequestParser();
String value = "t=1625212448369";
ProxyRequestHeader proxyHttpHeader = parser.parseHeader("HEADER_NAME", value);
assertTrue(proxyHttpHeader.isValid());
assertEquals(1625212448369L, proxyHttpHeader.getReceivedTimeMillis());
assertEquals(-1, proxyHttpHeader.getDurationTimeMicroseconds());
assertEquals(-1, proxyHttpHeader.getIdlePercent());
assertEquals(-1, proxyHttpHeader.getBusyPercent());
assertThat(proxyHttpHeader.isValid()).isTrue();
assertThat(1625212448369L).isEqualTo(proxyHttpHeader.getReceivedTimeMillis());
assertThat(-1).isEqualTo(proxyHttpHeader.getDurationTimeMicroseconds());
assertThat(-1).isEqualTo(proxyHttpHeader.getIdlePercent());
assertThat(-1).isEqualTo(proxyHttpHeader.getBusyPercent());
}

@Test
public void parseNotFoundReceived() {
UserRequestParser parser = new UserRequestParser();
String value = "D=123";
ProxyRequestHeader proxyHttpHeader = parser.parse(value);
assertFalse(proxyHttpHeader.isValid());
System.out.println(proxyHttpHeader);
ProxyRequestHeader proxyHttpHeader = parser.parseHeader("HEADER_NAME", value);
assertThat(proxyHttpHeader.isValid()).isFalse();
}

@Test
public void parseReceivedSeconds() {
UserRequestParser parser = new UserRequestParser();
String value = "t=1625212448.369";
ProxyRequestHeader proxyHttpHeader = parser.parseHeader("HEADER_NAME", value);
assertEquals(1625212448369L, proxyHttpHeader.getReceivedTimeMillis());
assertEquals(-1, proxyHttpHeader.getDurationTimeMicroseconds());
assertEquals(-1, proxyHttpHeader.getIdlePercent());
assertEquals(-1, proxyHttpHeader.getBusyPercent());
assertThat(1625212448369L).isEqualTo(proxyHttpHeader.getReceivedTimeMillis());
assertThat(-1).isEqualTo(proxyHttpHeader.getDurationTimeMicroseconds());
assertThat(-1).isEqualTo(proxyHttpHeader.getIdlePercent());
assertThat(-1).isEqualTo(proxyHttpHeader.getBusyPercent());
}

@Test
public void parseInvalidReceived() {
UserRequestParser parser = new UserRequestParser();
String value = "t=1625212448:369";
ProxyRequestHeader proxyHttpHeader = parser.parse(value);
assertFalse(proxyHttpHeader.isValid());
System.out.println(proxyHttpHeader);
ProxyRequestHeader proxyHttpHeader = parser.parseHeader("HEADER_NAME", value);
assertThat(proxyHttpHeader.isValid()).isFalse();
}

}

0 comments on commit 046d24f

Please sign in to comment.