use of com.quorum.tessera.api.SendRequest in project tessera by ConsenSys.
the class StressSendIT method sendToSingleRecipientUntilFailureOrMaxReached.
/**
* Quorum sends transaction with single public recipient key
*/
@Test
public void sendToSingleRecipientUntilFailureOrMaxReached() {
LOGGER.info("stress test starting");
final Party firstParty = partyHelper.findByAlias("A");
final Party secondParty = partyHelper.findByAlias("B");
byte[] transactionData = utils.createTransactionData();
final AtomicInteger sendCounter = new AtomicInteger(0);
final AtomicInteger invalidResults = new AtomicInteger(0);
final List<Thread> stressThreads = new ArrayList<>();
for (int i = 0; i < THREAD_COUNT; i++) {
final Thread stressThread = new Thread(() -> {
int currentCount = sendCounter.incrementAndGet();
while (currentCount < MAX_COUNT) {
final SendRequest sendRequest = new SendRequest();
sendRequest.setFrom(firstParty.getPublicKey());
sendRequest.setTo(secondParty.getPublicKey());
sendRequest.setPayload(transactionData);
try (Response response = client.target(firstParty.getQ2TUri()).path(SEND_PATH).request().post(Entity.entity(sendRequest, MediaType.APPLICATION_JSON))) {
if (response.getStatus() != 201) {
LOGGER.info("Response is not 201. MessageCount=" + currentCount);
sendCounter.addAndGet(MAX_COUNT);
invalidResults.incrementAndGet();
}
}
currentCount = sendCounter.incrementAndGet();
if (currentCount % 1000 == 0) {
LOGGER.info("currentCount={}", currentCount);
}
}
});
stressThread.start();
stressThreads.add(stressThread);
}
// wait for stress threads to finish
for (int i = 0; i < THREAD_COUNT; i++) {
try {
stressThreads.get(i).join();
} catch (InterruptedException e) {
LOGGER.error("Error while waiting for clients to stop.", e);
}
}
LOGGER.info("stress test finished");
assertThat(invalidResults.get()).isEqualTo(0);
}
use of com.quorum.tessera.api.SendRequest in project tessera by ConsenSys.
the class TransactionForwardingIT method sendNewTransaction.
private String sendNewTransaction(final Party party) {
final URI node = party.getQ2TUri();
final String from = party.getPublicKey();
SendRequest sendRequest = new SendRequest();
sendRequest.setFrom(from);
sendRequest.setPayload(transactionData);
LOGGER.debug("Sending {} to {}", sendRequest, node);
final Response response = party.getRestClient().target(node).path("/send").request().post(Entity.entity(sendRequest, MediaType.APPLICATION_JSON));
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(201);
LOGGER.debug("Sent {} to {}", sendRequest, node);
// check the call was success
final SendResponse result = response.readEntity(SendResponse.class);
LOGGER.debug("Response status : {}, body: {}", response.getStatus(), result);
assertThat(result.getKey()).isNotBlank();
return result.getKey();
}
use of com.quorum.tessera.api.SendRequest in project tessera by ConsenSys.
the class PrivacyIT method sendTransactionsWithFlagMismatched.
@Test
public void sendTransactionsWithFlagMismatched() {
Party sender = partyHelper.findByAlias(NodeAlias.A);
final String originalHash = sendContractCreationTransaction(PrivacyMode.PARTY_PROTECTION);
SendRequest secondRequest = new SendRequest();
secondRequest.setPayload(new RestUtils().createTransactionData());
secondRequest.setFrom(sender.getPublicKey());
List<String> recipientList = List.of(partyHelper.findByAlias(NodeAlias.B).getPublicKey());
secondRequest.setTo(recipientList.toArray(new String[recipientList.size()]));
secondRequest.setPrivacyFlag(PrivacyMode.STANDARD_PRIVATE.getPrivacyFlag());
secondRequest.setAffectedContractTransactions(originalHash);
Response secondResponse = sender.getRestClientWebTarget().path("send").request().post(Entity.entity(secondRequest, MIME_TYPE_JSON_2_1));
assertThat(secondResponse.getStatus()).isEqualTo(403);
}
use of com.quorum.tessera.api.SendRequest in project tessera by ConsenSys.
the class PrivacyIT method enhancedPrivacyTransactionsNotEnabled.
@Test
public void enhancedPrivacyTransactionsNotEnabled() {
Party legacySender = partyHelper.findByAlias(NodeAlias.D);
SendRequest sendRequest = new SendRequest();
sendRequest.setPayload(new RestUtils().createTransactionData());
sendRequest.setFrom(legacySender.getPublicKey());
List<String> recipientList = List.of(partyHelper.findByAlias(NodeAlias.A).getPublicKey());
sendRequest.setTo(recipientList.toArray(new String[recipientList.size()]));
sendRequest.setPrivacyFlag(PrivacyMode.PARTY_PROTECTION.getPrivacyFlag());
sendRequest.setAffectedContractTransactions(new String[0]);
Response response = legacySender.getRestClientWebTarget().path("send").request().post(Entity.entity(sendRequest, MIME_TYPE_JSON_2_1));
assertThat(response.getStatus()).isEqualTo(403);
}
use of com.quorum.tessera.api.SendRequest in project tessera by ConsenSys.
the class PrivacyIT method sendPSVTransactionsWithRecipientsMismatched.
@Test
public void sendPSVTransactionsWithRecipientsMismatched() {
Party sender = partyHelper.findByAlias(NodeAlias.A);
final String originalHash = sendContractCreationTransaction(PrivacyMode.PRIVATE_STATE_VALIDATION);
SendRequest secondRequest = new SendRequest();
secondRequest.setPayload(new RestUtils().createTransactionData());
secondRequest.setFrom(sender.getPublicKey());
List<String> anotherList = List.of(partyHelper.findByAlias(NodeAlias.B).getPublicKey(), partyHelper.findByAlias(NodeAlias.C).getPublicKey());
secondRequest.setTo(anotherList.toArray(new String[anotherList.size()]));
secondRequest.setPrivacyFlag(PrivacyMode.PRIVATE_STATE_VALIDATION.getPrivacyFlag());
secondRequest.setAffectedContractTransactions(originalHash);
secondRequest.setExecHash("execHash");
Response secondResponse = sender.getRestClientWebTarget().path("send").request().post(Entity.entity(secondRequest, MIME_TYPE_JSON_2_1));
assertThat(secondResponse.getStatus()).isEqualTo(403);
}
Aggregations