Skip to content

Commit

Permalink
Merge pull request #149 from soramitsu/scn/multiplay-batches-queries
Browse files Browse the repository at this point in the history
Scn/multiplay batches queries
  • Loading branch information
timofeevmd authored Sep 18, 2024
2 parents 7429193 + 3794007 commit 6fd0218
Show file tree
Hide file tree
Showing 11 changed files with 66,673 additions and 11,310 deletions.
6 changes: 0 additions & 6 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
Expand All @@ -23,7 +18,6 @@
</buildSpec>
<natures>
<nature>org.jetbrains.kotlin.core.kotlinNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
<linkedResources>
Expand Down
25 changes: 25 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,41 @@
<version>${gatling.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.hyperledger.iroha-java</groupId>
<artifactId>block</artifactId>
<version>${iroha-java.version}</version>
</dependency>
<dependency>
<groupId>com.github.hyperledger.iroha-java</groupId>
<artifactId>codegen</artifactId>
<version>${iroha-java.version}</version>
</dependency>
<dependency>
<groupId>com.github.hyperledger.iroha-java</groupId>
<artifactId>client</artifactId>
<version>${iroha-java.version}</version>
</dependency>
<dependency>
<groupId>com.github.hyperledger.iroha-java</groupId>
<artifactId>admin-client</artifactId>
<version>${iroha-java.version}</version>
</dependency>
<dependency>
<groupId>com.github.hyperledger.iroha-java</groupId>
<artifactId>tutorial</artifactId>
<version>${iroha-java.version}</version>
</dependency>
<dependency>
<groupId>com.github.hyperledger.iroha-java</groupId>
<artifactId>model</artifactId>
<version>${iroha-java.version}</version>
</dependency>
<dependency>
<groupId>com.github.hyperledger.iroha-java</groupId>
<artifactId>test-tools</artifactId>
<version>${iroha-java.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/Configs/LoadProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static OpenInjectionStep getMaxPerformanceOpenProfile() {
return incrementUsersPerSec(Double.parseDouble(System.getProperty("concurrentUsers")))//20
.times(Integer.parseInt(System.getProperty("times")))//5
.eachLevelLasting(Integer.parseInt(System.getProperty("stageDuration")))//5
.separatedByRampsLasting(Integer.parseInt(System.getProperty("rampDuration")))//5
//.separatedByRampsLasting(Integer.parseInt(System.getProperty("rampDuration")))//5
.startingFrom(Integer.parseInt(System.getProperty("startingFrom")));//20
}

Expand Down
120 changes: 119 additions & 1 deletion src/test/java/requests/Queries.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package requests;

import io.gatling.javaapi.core.ChainBuilder;
import javassist.bytecode.ByteArray;
import jp.co.soramitsu.iroha2.CryptoUtils;
import jp.co.soramitsu.iroha2.ExtensionsKt;
import jp.co.soramitsu.iroha2.generated.SignedQuery;
import jp.co.soramitsu.iroha2.generated.*;
import jp.co.soramitsu.iroha2.query.QueryAndExtractor;
import jp.co.soramitsu.iroha2.query.QueryBuilder;

import java.util.List;
import java.util.ArrayList;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.http;
import static jp.co.soramitsu.iroha2.client.Iroha2Client.QUERY_ENDPOINT;

public class Queries extends Constants {

Expand Down Expand Up @@ -183,6 +189,118 @@ public class Queries extends Constants {
}))
);

/*
отправить запрос гатлингом
проверить есть ли батчи
если батчи есть
отправить дозапросы на эти батчи
*/

/*private static QueryAndExtractor queryFindAllAsset;
private static BatchedResponse responseDecoded;
private static byte[] response;
public static ChainBuilder paginatedQueryPostFindAllAssets = exec(feed(CSV_FEEDER)).exec(feed(PEERS_FEEDER))
.exec(session -> {
ForwardCursor cursor = null;
queryFindAllAsset = QueryBuilder
.findAllAssets()
.account(ExtensionsKt.asAccountId(session.getString("anotherDevAccountIdSender")))
.buildSigned(CryptoUtils.keyPairFromHex(
session.getString("publicKeySender"),
session.getString("privateKeySender")));
return session;
}
)
.exec(http("checkBatchesQuery")
.post(session -> {
return session.getString("peer") + URL_QUERY;
}
)
.body(ByteArrayBody(session -> {
return SignedQuery.Companion.encode(queryFindAllAsset.getQuery());
}
)
//сохранил тело ответа как байт массив
).check(bodyBytes().saveAs("fullResponse")) // save id
)
.exec(session -> {
//реализовать работу с результатом предыдущего запроса
return session;
}
)
.exec(http("findAllAssets")
.post(session -> {
return session.getString("peer") + URL_QUERY;
}
)
.body(ByteArrayBody(session -> {
ForwardCursor cursor = null;
QueryAndExtractor queryFindAllAsset = QueryBuilder
.findAllAssets()
.account(ExtensionsKt.asAccountId(session.getString("anotherDevAccountIdSender")))
.buildSigned(CryptoUtils.keyPairFromHex(
session.getString("publicKeySender"),
session.getString("privateKeySender")));
var responseDecoded = sendQueryRequest(queryFindAllAsset, cursor);
BatchedResponse.V1 decodedCursor = null;
decodedCursor = (BatchedResponse.V1) responseDecoded.;
if (decodedCursor.getBatchedResponseV1().getCursor() == null) {
var finalResult = queryFindAllAsset.getResultExtractor().extract((responseDecoded);
return finalResult;
} else {
List<QueryOutputBox> resultList = getQueryResultWithCursor(queryFindAllAsset, decodedCursor.getBatchedResponseV1().getCursor());
resultList.add(responseDecoded.getBatch());
var finalResult = queryFindAllAsset.getResultExtractor().extract(new BatchedResponse.V1(
new BatchedResponseV1(new QueryOutputBox.Vec(resultList), new ForwardCursor())));
return finalResult;
}
}
)
)
);
private static BatchedResponse<QueryOutputBox> sendQueryRequest(QueryAndExtractor queryAndExtractor, ForwardCursor cursor) {
if (cursor == null) {
return client.post(getApiUrl() + QUERY_ENDPOINT,
request -> request.setBody(SignedQuery.encode(queryAndExtractor.getQuery()))
).thenApply(response -> {
byte[] responseBody = response;
return BatchedResponse.Companion.decode(responseBody);
});
} else {
return client.post(getApiUrl() + QUERY_ENDPOINT,
request -> {
request.parameter("query", cursor.getQuery());
request.parameter("cursor", cursor.getCursor() != null ? cursor.getCursor().getU64() : null);
}
).thenApply(response -> {
byte[] responseBody = response.body();
return BatchedResponseV1.Companion.decode(responseBody);
});
}
}
private static List<QueryOutputBox> getQueryResultWithCursor(QueryAndExtractor queryAndExtractor, ForwardCursor queryCursor) {
if (queryCursor == null) {
queryCursor = new ForwardCursor();
}
List<QueryOutputBox> resultList = new ArrayList<>();
BatchedResponseV1<QueryOutputBox> responseDecoded = sendQueryRequest(queryAndExtractor, queryCursor);
resultList.add(responseDecoded.getBatch());
var cursor = responseDecoded.getCursor();
if (cursor.getCursor() == null) {
return resultList;
} else {
resultList.addAll(getQueryResultWithCursor(queryAndExtractor, cursor));
return resultList;
}
}*/

public static ChainBuilder queryPostFindAllAccounts = exec(feed(CSV_FEEDER)).exec(feed(PEERS_FEEDER))
.exec(
http("findAllAccounts")
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/scenarious/GeneralTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ public class GeneralTransaction {

public static ScenarioBuilder txsTransferAsset = scenario("transfer asset")
.feed(csv("preconditionList.csv").circular())
.exec(Transactions.postTransferAsset)
.exec(Transactions.postTransferAsset)
.exec(Transactions.postTransferAsset)
.exec(Transactions.postTransferAsset)
.exec(Transactions.postTransferAsset);
}
Loading

0 comments on commit 6fd0218

Please sign in to comment.