Skip to content

Conversation

@danieljbruce
Copy link
Contributor

@danieljbruce danieljbruce commented Jul 29, 2024

Summary:

This PR reduces all of those custom if statements down to one line of code in the ReadRows mock implementation cutting the ReadRows mock implementation down to about half the size so that in the next PR it is easy to make a modular version of the ReadRows mock implementation.

Background:

As requested, the eventual goal is to address these TODOs. So far, two PRs have already been merged to take steps toward this:

  1. this PR eliminates duplicate code and adds interfaces to simplify data flows
  2. this PR eliminated the duplicate copy of the ReadRows service

Changes:

  • Instead of having a global debug log, define a debugLog and pass the debugLog into the readrows service when creating the readrows service. This involves adding a debug log to the ReadRowsServiceParameters.
  • Add a DebugLog interface as it is now needed to specify the type for the debugLog dependency passed in to various functions now that the global debugLog has been eliminated.
  • Add an interface ReadRowsWritableStream for the ServerWritableStream<x,x> type used everywhere for conciseness. Then replace all references to ServerWritableStream<x,x> with the ReadRowsWritableStream type.
  • In readRowsImpl.ts replace all those repeated if statements with a call to generateChunksFromRequest. generateChunksFromRequest then calls a new generateChunks function with calculated keyTo and keyFrom values. keyTo and keyFrom are both calculated using a new getSelectedKey method which uses a default key if it is provided and otherwise uses the key provided in the open/close properties of the request.
  • Every time a ReadRows service is defined a debugLog is passed in as now this parameter is required.

Next Steps:

The readRowsImpl function will be broken down into classes as required by the TODO.

Only ignore keyFrom and keyTo when they are undefined and not just when they are Falsy.
The old service has been generalized enough to mock correct server behaviour.
they are undefined anyway.
@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: l Pull request size is large. labels Jul 29, 2024
@danieljbruce danieljbruce changed the title test: TODO test: Eliminate repeated if statements in the ReadRows mock service reducing the size of it significantly Jul 29, 2024
console.log(text);
}
}

Copy link
Contributor Author

@danieljbruce danieljbruce Jul 29, 2024

Choose a reason for hiding this comment

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

DebugLog is just being moved from the service to here in the test

if (DEBUG) {
console.log(text);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has just been moved to the test and will be passed into the service.

chunkSize: serviceParameters.chunkSize,
valueSize: serviceParameters.valueSize,
});
const chunks = generateChunksFromRequest(stream.request, serviceParameters);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This single line of code is a substitute for all of the code deleted previous to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code for each if statement now lives in getKeyValue. generateChunksFromRequest calls generateChunks making 2 calls to getSelectedKey each making 2 calls to getKeyValue.

@danieljbruce danieljbruce marked this pull request as ready for review July 29, 2024 20:52
@danieljbruce danieljbruce requested review from a team as code owners July 29, 2024 20:52
@danieljbruce danieljbruce removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Aug 12, 2024
@danieljbruce danieljbruce merged commit fa70453 into 3527322442-to-main-2 Aug 12, 2024
@danieljbruce danieljbruce deleted the 3527322442-refactor-the-test-into-classes-3 branch August 12, 2024 20:11
danieljbruce added a commit that referenced this pull request Sep 23, 2024
* test: begin to refactor the mock service (#1447)

* Use prettyPrintRequest from readRowsImpl1

* Define interfaces for creating a Bigtable service

* Remove keyFrom and keyTo from each test

* Define the service inline for standard keys errors

* Add a comment about the refactor steps I am doing

* Add a header to the service parameters file

* Use the ChunkGeneratorParameters interface

* Simplify the diff by creating local variables

* Remove comment

* Eliminate chunks per response constant

* Change imports

* Replace with as ServerImplementationInterface

* Update test/readrows.ts

Co-authored-by: Leah E. Cole <[email protected]>

* Add a second test for an error at a random pos

* Add some comments for documentation

* Chunk generation - add the parameter

* Added comments to all the interfaces

* Fix a regression bug from the merge

---------

Co-authored-by: Leah E. Cole <[email protected]>

* test: Eliminate the second ReadRows Service and use a generalized version of the first ReadRows (#1457)

* Use prettyPrintRequest from readRowsImpl1

* Define interfaces for creating a Bigtable service

* Remove keyFrom and keyTo from each test

* Define the service inline for standard keys errors

* Add a comment about the refactor steps I am doing

* Add a header to the service parameters file

* Use the ChunkGeneratorParameters interface

* Simplify the diff by creating local variables

* Remove comment

* Eliminate chunks per response constant

* Change imports

* Set up the second ReadRows service to use params

* Remove duplicate copy of generate chunks from serv

* Remove second copy of isKeyInRowSet

* Eliminate duplicate copies of the debug log

* Fix a bug for the to and from service parameters

Only ignore keyFrom and keyTo when they are undefined and not just when they are Falsy.

* Add cancel back into the mock service for testing

* Add variables to match service 1

* Add one more check to match the other service

* Remove usages of ReadRows2Impl

* Remove the new service

The old service has been generalized enough to mock correct server behaviour.

* Moved the position of the comment for 150 rows

* Eliminate setting keyTo and keyFrom

they are undefined anyway.

* Add a second test for an error at a random pos

* Add some comments for documentation

* Chunk generation - add the parameter

* Added comments to all the interfaces

* Delete file

* Change splitted to split

* Remove export

* Don’t rename the interfaces

There is no point

* Increase Windows timeout

* Provide functions to eliminate if statements

* Eliminate the if statements

Make a direct call to generateChunksFromRequest

* Revert "Eliminate the if statements"

This reverts commit 0996e89.

* Revert "Provide functions to eliminate if statements"

This reverts commit 4a4761f.

* Change any’s to string | undefined

* Eliminate duplicate code for setting timeouts

* remove only

* Update test/readrows.ts

Co-authored-by: Leah E. Cole <[email protected]>

* Update test/readrows.ts

Co-authored-by: Leah E. Cole <[email protected]>

* Update test/readrows.ts

Co-authored-by: Leah E. Cole <[email protected]>

* Update test/readrows.ts

Co-authored-by: Leah E. Cole <[email protected]>

* Update test/readrows.ts

Co-authored-by: Leah E. Cole <[email protected]>

* Update test/readrows.ts

Co-authored-by: Leah E. Cole <[email protected]>

* Update test/readrows.ts

Co-authored-by: Leah E. Cole <[email protected]>

---------

Co-authored-by: Leah E. Cole <[email protected]>

* test: Eliminate repeated if statements in the ReadRows mock service reducing the size of it significantly (#1460)

* Use prettyPrintRequest from readRowsImpl1

* Define interfaces for creating a Bigtable service

* Remove keyFrom and keyTo from each test

* Define the service inline for standard keys errors

* Add a comment about the refactor steps I am doing

* Add a header to the service parameters file

* Use the ChunkGeneratorParameters interface

* Simplify the diff by creating local variables

* Remove comment

* Eliminate chunks per response constant

* Change imports

* Set up the second ReadRows service to use params

* Remove duplicate copy of generate chunks from serv

* Remove second copy of isKeyInRowSet

* Eliminate duplicate copies of the debug log

* Fix a bug for the to and from service parameters

Only ignore keyFrom and keyTo when they are undefined and not just when they are Falsy.

* Add cancel back into the mock service for testing

* Add variables to match service 1

* Add one more check to match the other service

* Remove usages of ReadRows2Impl

* Remove the new service

The old service has been generalized enough to mock correct server behaviour.

* Moved the position of the comment for 150 rows

* Eliminate setting keyTo and keyFrom

they are undefined anyway.

* Add a second test for an error at a random pos

* Add some comments for documentation

* Chunk generation - add the parameter

* Added comments to all the interfaces

* Group the property getter into a function

* Group key selection into functions

* Fix typo: default key

* Documentation for isInRowSet

* Eliminate variable - move function inline

* Omit optional selector on stream

* Create ReadRowsWritableStream interface

* Use new interface, remove ServerWritableStream

* Don’t pass the whole stream into helpers

* Add a function for generating the chunks

* The debug log should be a pass through parameter

* Solve compiler errors resulting immediately from

merge

* Add debugLog parameter to various functions

* Add return type

* Remove exports - functions are only used in this

module

* Revise merge correction

* Remove TODO for the stream type

* Update the getKeyValue function

* Eliminate place where debug log is needed

* Run linter

* test: Break the ReadRows service down into classes instead of a single long function (#1461)

* Use prettyPrintRequest from readRowsImpl1

* Define interfaces for creating a Bigtable service

* Remove keyFrom and keyTo from each test

* Define the service inline for standard keys errors

* Add a comment about the refactor steps I am doing

* Add a header to the service parameters file

* Use the ChunkGeneratorParameters interface

* Simplify the diff by creating local variables

* Remove comment

* Eliminate chunks per response constant

* Change imports

* Set up the second ReadRows service to use params

* Remove duplicate copy of generate chunks from serv

* Remove second copy of isKeyInRowSet

* Eliminate duplicate copies of the debug log

* Fix a bug for the to and from service parameters

Only ignore keyFrom and keyTo when they are undefined and not just when they are Falsy.

* Add cancel back into the mock service for testing

* Add variables to match service 1

* Add one more check to match the other service

* Remove usages of ReadRows2Impl

* Remove the new service

The old service has been generalized enough to mock correct server behaviour.

* Moved the position of the comment for 150 rows

* Eliminate setting keyTo and keyFrom

they are undefined anyway.

* Add a second test for an error at a random pos

* Add some comments for documentation

* Chunk generation - add the parameter

* Added comments to all the interfaces

* Group the property getter into a function

* Group key selection into functions

* Fix typo: default key

* Documentation for isInRowSet

* Eliminate variable - move function inline

* Omit optional selector on stream

* Create ReadRowsWritableStream interface

* Use new interface, remove ServerWritableStream

* Don’t pass the whole stream into helpers

* Add a function for generating the chunks

* The debug log should be a pass through parameter

* Add some TODOs about how to address this next

* Pull send response into a class

* Create a dedicated class for defining the service

* Change name to readRowsRequestHandler

* Pull the function that generates the chunks into

Separate module

* Generate documentation

* Add more documentation to the Service class

* Add debugLog as a method parameter

* Solve compiler errors resulting immediately from

merge

* Add debugLog parameter to various functions

* Add return type

* Remove exports - functions are only used in this

module

* Revise merge correction

* Remove TODO for the stream type

* Update the getKeyValue function

* Eliminate place where debug log is needed

* Run linter

* Eliminate the function that creates a service

Add a factory method instead

* Add documentation for the constructor

* Remove the TODO

* Set the timeout for the test

* Increase the timeout

* Eliminate ternary statement

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* Add a couple of comments

* re-write the ternary expression

---------

Co-authored-by: Leah E. Cole <[email protected]>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigtable Issues related to the googleapis/nodejs-bigtable API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants