Skip to content

Conversation

MakarovS
Copy link
Contributor

@MakarovS MakarovS commented Oct 25, 2019

Overview

Remove <T extends Service> T getService(String serviceName, Class<T> serviceClass) from TestKit in favour of testing read requests to service via service schema.


See: https://jira.bf.local/browse/ECR-3723

Definition of Done

  • There are no TODOs left in the code
  • Change is covered by automated tests
  • The coding guidelines are followed
  • Public API has Javadoc
  • Method preconditions are checked and documented in the Javadoc of the method
  • Changelog is updated if needed (in case of notable or breaking changes)
  • The continuous integration build passes

}

@Test
void findTransactionsInPool(TestKit testKit) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestKit.findTransactionsInPool() is tested in afterCommitSubmitsTransaction test.

TestSchema.class);
}

static void checkIfServiceEnabled(TestKit testKit, String serviceName, int serviceId) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we create separate TestKitTestUtils and place it there or is this class good enough? If so, rename this class?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could live here, I think.

// Check that TestService2 API is mounted
Node serviceNode = service.getNode();
EmulatedNode emulatedTestKitNode = testKit.getEmulatedNode();
assertThat(serviceNode.getPublicKey())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we retrieve public key from core schema instead and validate them against emulatedTestKitNode public key or is that unnecessary?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a separate test for getEmulatedNode? I think it makes sense to test it there using the core schema, but not here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do, but not using core schema (we just check that the node type (validator or auditor) is correct and keys are not null). Should I put this PR on WIP until #1185 is merged and then add the full test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a test for that, need a merged #1185 though

* cast to given class
*/
public <T extends Service> T getService(String serviceName, Class<T> serviceClass) {
Service service = serviceRuntime.getServiceInstanceByName(serviceName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getServiceInstanceByName in the Runtime and ServiceWrapper are probably no longer needed.

// Check that TestService2 API is mounted
Node serviceNode = service.getNode();
EmulatedNode emulatedTestKitNode = testKit.getEmulatedNode();
assertThat(serviceNode.getPublicKey())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a separate test for getEmulatedNode? I think it makes sense to test it there using the core schema, but not here.

// Create two blocks with no transactions, so two afterCommit transactions are stored in
// the transaction pool
Block block1 = testKit.createBlock();
Block block2 = testKit.createBlockWithTransactions();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the difference (createBlock vs createBlockWithTransactions), the comment above says no transactions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use createBlock for second time it would create a block with the first afterCommit transaction from pool, and we want to keep it there - that's why createBlockWithTransactions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an unclear (from the source) distinction that warrants an explanation in the source, because it is relied upon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc of this method contains this distinction - In-pool transactions will be ignored.

Added an additional comment for this line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc does not show the intent of the writer of this method.

TestSchema.class);
}

static void checkIfServiceEnabled(TestKit testKit, String serviceName, int serviceId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could live here, I think.

@dmitry-timofeev dmitry-timofeev merged commit 8e864a7 into ECR-3571 Oct 29, 2019
@dmitry-timofeev dmitry-timofeev deleted the remove_get_service branch October 29, 2019 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants