Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#noissue] Fix proxy-user plugin test #9855

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}

}