The same stream instance cannot be materialized twice:
1. stream.count()
2. stream.collect(toImmutableList())
Materialize the stream only once and use the size() method of created
collection to perform optimized hash map creation.
Add a ref advertisement integration test in slave mode, to ensure that
DefaultRefFilter#visibleChangesByScan() is get called, so that such a
regression can be prevented in future.
Bug: Issue 10240
Change-Id: If87037f8f0c1b0b2a2d81370296677b28b0ff448