-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from IvanKondrashkov/homework-11
feat: Добавлены нагрузочные тесты, модуль hw09-back
- Loading branch information
Showing
7 changed files
with
171 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
62748 | ||
57245 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
hw09-back/src/main/groovy/ru/otus/homework/util/LocalDateTimeAdapter.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ru.otus.homework.util | ||
|
||
import java.time.LocalDateTime | ||
import com.google.gson.TypeAdapter | ||
import com.google.gson.stream.JsonToken | ||
import com.google.gson.stream.JsonReader | ||
import com.google.gson.stream.JsonWriter | ||
import java.time.format.DateTimeFormatter | ||
|
||
class LocalDateTimeAdapter extends TypeAdapter<LocalDateTime> { | ||
private final DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME | ||
|
||
@Override | ||
void write(JsonWriter jsonWriter, LocalDateTime date) throws IOException { | ||
if (date == null) { | ||
jsonWriter.nullValue() | ||
return | ||
} | ||
jsonWriter.value(date.format(formatter)) | ||
} | ||
|
||
@Override | ||
LocalDateTime read(JsonReader jsonReader) throws IOException { | ||
if (jsonReader.peek() == JsonToken.NULL) { | ||
jsonReader.nextNull() | ||
return null | ||
} | ||
return LocalDateTime.parse(jsonReader.nextString(), formatter) | ||
} | ||
} |
133 changes: 133 additions & 0 deletions
133
hw09-back/src/test/groovy/ru/otus/homework/perfomans/PerfomansTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package ru.otus.homework.perfomans | ||
|
||
import com.google.gson.Gson | ||
import com.google.gson.GsonBuilder | ||
import io.micronaut.context.annotation.Property | ||
import io.micronaut.test.extensions.spock.annotation.MicronautTest | ||
import java.time.Duration | ||
import java.time.LocalDateTime | ||
import spock.lang.Specification | ||
import ru.otus.homework.model.Task | ||
import ru.otus.homework.model.Action | ||
import org.apache.http.entity.ContentType | ||
import ru.otus.homework.util.LocalDateTimeAdapter | ||
import us.abstracta.jmeter.javadsl.core.TestPlanStats | ||
import static us.abstracta.jmeter.javadsl.JmeterDsl.*; | ||
|
||
@MicronautTest | ||
@Property(name = "datasources.default.driver-class-name", value = "org.testcontainers.jdbc.ContainerDatabaseDriver") | ||
@Property(name = "datasources.default.url", value = "jdbc:tc:postgresql:///db") | ||
class PerfomansTest extends Specification { | ||
Task task | ||
Action action | ||
Gson gson | ||
|
||
String taskId | ||
String actionId | ||
|
||
static final String BASE_URL = "http://localhost:9090" | ||
|
||
def setup() { | ||
task = new Task( | ||
name: "learning", | ||
description: "read book", | ||
startDate: LocalDateTime.of(2024, 11, 1, 0, 0), | ||
endDate: LocalDateTime.of(2024, 11, 10, 0, 0), | ||
) | ||
action = new Action( | ||
name: "read", | ||
description: "read math", | ||
startDate: LocalDateTime.of(2024, 11, 2, 0, 0), | ||
endDate: LocalDateTime.of(2024, 11, 3, 0, 0), | ||
task: task | ||
) | ||
gson = new GsonBuilder() | ||
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeAdapter()) | ||
.serializeNulls() | ||
.create() | ||
} | ||
|
||
void cleanup() { | ||
task = null | ||
action = null | ||
gson = null | ||
} | ||
|
||
def "saveTask"() { | ||
when: | ||
TestPlanStats stats = testPlan( | ||
threadGroup(10, 20, | ||
httpSampler(BASE_URL + "/tasks") | ||
.post(gson.toJson(task), ContentType.APPLICATION_JSON) | ||
.children( | ||
jsr223PostProcessor( | ||
"if (prev.responseCode == '400') { prev.successful = true }") | ||
) | ||
), | ||
jtlWriter("build/jtls"), | ||
htmlReporter("build/reports/jmeter") | ||
).run() | ||
|
||
then: | ||
stats.overall().sampleTimePercentile99() <= Duration.ofSeconds(1) | ||
} | ||
|
||
def "saveAction"() { | ||
when: | ||
TestPlanStats stats = testPlan( | ||
threadGroup(10, 20, | ||
httpSampler(BASE_URL + "/actions") | ||
.post(gson.toJson(action), ContentType.APPLICATION_JSON) | ||
.children( | ||
jsr223PostProcessor( | ||
"if (prev.responseCode == '400') { prev.successful = true }") | ||
) | ||
), | ||
jtlWriter("build/jtls"), | ||
htmlReporter("build/reports/jmeter") | ||
).run() | ||
|
||
then: | ||
stats.overall().sampleTimePercentile99() <= Duration.ofSeconds(1) | ||
} | ||
|
||
def "findByIdTask"() { | ||
when: | ||
TestPlanStats stats = testPlan( | ||
threadGroup(10, 20, | ||
httpSampler(BASE_URL + "/tasks") | ||
.post(gson.toJson(task), ContentType.APPLICATION_JSON) | ||
.children( | ||
jsonExtractor(taskId, "[].id"), | ||
debugPostProcessor() | ||
), | ||
httpSampler(BASE_URL + "/tasks/${taskId}") | ||
), | ||
jtlWriter("build/jtls"), | ||
htmlReporter("build/reports/jmeter") | ||
).run() | ||
|
||
then: | ||
stats.overall().sampleTimePercentile99() <= Duration.ofSeconds(1) | ||
} | ||
|
||
def "findByIdAction"() { | ||
when: | ||
TestPlanStats stats = testPlan( | ||
threadGroup(10, 20, | ||
httpSampler(BASE_URL + "/actions") | ||
.post(gson.toJson(action), ContentType.APPLICATION_JSON) | ||
.children( | ||
jsonExtractor(actionId, "[].id"), | ||
debugPostProcessor() | ||
), | ||
httpSampler(BASE_URL + "/actions/${actionId}") | ||
), | ||
jtlWriter("build/jtls"), | ||
htmlReporter("build/reports/jmeter") | ||
).run() | ||
|
||
then: | ||
stats.overall().sampleTimePercentile99() <= Duration.ofSeconds(1) | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.