Skip to content

Commit

Permalink
Further refinement on refactors to make code even simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
rabelenda-abstracta committed Nov 23, 2023
1 parent 387b9ae commit 539e029
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.Base64;
Expand Down Expand Up @@ -47,11 +48,11 @@
import us.abstracta.jmeter.javadsl.engines.BaseRemoteEngineApiClient;
import us.abstracta.jmeter.javadsl.util.TestResource;


public class AzureClient extends BaseRemoteEngineApiClient {

private static final Logger LOG = LoggerFactory.getLogger(AzureClient.class);
private static final String USER_AGENT = getUserAgent();
private static final int HTTP_NOT_FOUND = 404;

private final String tenantId;
private final String clientId;
Expand Down Expand Up @@ -267,7 +268,7 @@ public ResourceGroup findResourceGroup(String name, Subscription subscription)
private <T> Optional<T> execOptionalApiCall(Call<T> call) throws IOException {
retrofit2.Response<T> response = call.execute();
if (!response.isSuccessful()) {
if (response.code() == HTTP_NOT_FOUND) {
if (response.code() == HttpURLConnection.HTTP_NOT_FOUND) {
return Optional.empty();
}
try (ResponseBody errorBody = response.errorBody()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ public void shouldDisplayGraphsAndSummaryWhenRunTestPlanWithDashboard(TestInfo t
);
}

@Test
public void shouldThrowUnsupportedOperationWhenShowInGuiOnDashboardVisualizer() {
DashboardVisualizer dashboardVisualizer = new DashboardVisualizer();

assertThrows(UnsupportedOperationException.class, dashboardVisualizer::showInGui);
}
@Test
public void shouldThrowUnsupportedOperationWhenShowInGuiOnDashboardVisualizer() {
assertThrows(UnsupportedOperationException.class, () -> new DashboardVisualizer().showInGui());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,13 @@ public void shouldSendGraphqlQueryToServerWhenGraphqlSamplerWithHttpGet()
).run();
verify(getRequestedFor(anyUrl()).withQueryParam("query", equalTo(QUERY)));
}

@Test
public void shouldThrowIllegalArgumentWhenGraphqlSamplerWithInvalidVariable() {
DslGraphqlSampler sampler = graphqlSampler("http://localhost", "{ user(id: 1){ name } }");
assertThrows(IllegalArgumentException.class, () -> sampler.variable("invalidVar", new Object()));
}

@Test
public void shouldHandleInvalidJsonInput() {
DslGraphqlSampler sampler = graphqlSampler("http://localhost", "{ user(id: 1){ name } }");
sampler.variablesJson("invalidJson");
}



@Nested
public class CodeBuilderTest extends MethodCallBuilderTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,10 @@ private void addStage(Stage stage) {

private boolean isSimpleThreadGroup() {
return stages.size() <= 1
|| stages.size() == 2 && (
ZERO.equals(stages.get(0).threadCount())
|| stages.get(0).threadCount().equals(stages.get(1).threadCount()))
|| stages.size() == 3 && (
ZERO.equals(stages.get(0).threadCount())
&& stages.get(1).threadCount().equals(stages.get(2).threadCount()));
|| stages.size() == 2 && (ZERO.equals(stages.get(0).threadCount()) || stages.get(0)
.threadCount().equals(stages.get(1).threadCount()))
|| stages.size() == 3 && (ZERO.equals(stages.get(0).threadCount()) && stages.get(1)
.threadCount().equals(stages.get(2).threadCount()));
}

/**
Expand Down Expand Up @@ -246,10 +244,9 @@ private Object getPrevThreadsCount() {
* termination condition).
* <p>
* <b>Setting this property to -1 is in general not advised</b>, since you
* might
* inadvertently end up running a test plan without limits consuming unnecessary
* computing power. Prefer specifying a big value as a safe limit for iterations
* or duration instead.
* might inadvertently end up running a test plan without limits consuming
* unnecessary computing power. Prefer specifying a big value as a safe limit
* for iterations or duration instead.
* @return the thread group for further configuration or usage.
* @throws IllegalStateException when adding iterations would result in not supported JMeter
* thread group.
Expand Down Expand Up @@ -286,10 +283,12 @@ public DslDefaultThreadGroup holdIterating(String iterations) {

private void checkIterationsPreConditions() {
boolean isJustRamp = stages.size() == 1 && !ZERO.equals(stages.get(0).threadCount());
boolean isJustDelayAndRamp = stages.size() == 2 && ZERO.equals(stages.get(0).threadCount()) && !ZERO.equals(stages.get(1).threadCount());

boolean isJustDelayAndRamp =
stages.size() == 2 && ZERO.equals(stages.get(0).threadCount()) && !ZERO.equals(
stages.get(1).threadCount());
if (!(isJustRamp || isJustDelayAndRamp)) {
throw new IllegalStateException("Holding for iterations is only supported after initial hold and ramp, or ramp.");
throw new IllegalStateException(
"Holding for iterations is only supported after initial hold and ramp, or ramp.");
}
if (ZERO.equals(getLastStage().threadCount())) {
throw new IllegalStateException("Can't hold for iterations with no threads.");
Expand Down

0 comments on commit 539e029

Please sign in to comment.