[GitHub] spark pull request #20983: [SPARK-23747][Structured Streaming] Add EpochCoor...
Github user asfgit closed the pull request at: https://github.com/apache/spark/pull/20983 --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #20983: [SPARK-23747][Structured Streaming] Add EpochCoor...
Github user efimpoberezkin commented on a diff in the pull request: https://github.com/apache/spark/pull/20983#discussion_r180679855 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/streaming/continuous/EpochCoordinatorSuite.scala --- @@ -0,0 +1,225 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + *http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.sql.streaming.continuous + +import org.mockito.InOrder +import org.mockito.Matchers.{any, eq => eqTo} +import org.mockito.Mockito._ +import org.scalatest.BeforeAndAfterEach +import org.scalatest.mockito.MockitoSugar + +import org.apache.spark._ +import org.apache.spark.rpc.RpcEndpointRef +import org.apache.spark.sql.execution.streaming.continuous._ +import org.apache.spark.sql.sources.v2.reader.streaming.{ContinuousReader, PartitionOffset} +import org.apache.spark.sql.sources.v2.writer.WriterCommitMessage +import org.apache.spark.sql.sources.v2.writer.streaming.StreamWriter +import org.apache.spark.sql.test.SharedSparkSession + +class EpochCoordinatorSuite + extends SparkFunSuite +with SharedSparkSession +with MockitoSugar +with BeforeAndAfterEach { + + private var epochCoordinator: RpcEndpointRef = _ + + private var writer: StreamWriter = _ + private var query: ContinuousExecution = _ + private var orderVerifier: InOrder = _ + + override def beforeEach(): Unit = { +val reader = mock[ContinuousReader] +writer = mock[StreamWriter] +query = mock[ContinuousExecution] +orderVerifier = inOrder(writer, query) + +epochCoordinator + = EpochCoordinatorRef.create(writer, reader, query, "test", 1, spark, SparkEnv.get) + } + + override def afterEach(): Unit = { +SparkEnv.get.rpcEnv.stop(epochCoordinator) + } + + test("single epoch") { +setWriterPartitions(3) +setReaderPartitions(2) + +commitPartitionEpoch(0, 1) +commitPartitionEpoch(1, 1) +commitPartitionEpoch(2, 1) +reportPartitionOffset(0, 1) +reportPartitionOffset(1, 1) + +// Here and in subsequent tests this is called to make a synchronous call to EpochCoordinator +// so that mocks would have been acted upon by the time verification happens +makeSynchronousCall() + +verifyCommit(1) + } + + test("single epoch, all but one writer partition has committed") { +setWriterPartitions(3) +setReaderPartitions(2) + +commitPartitionEpoch(0, 1) +commitPartitionEpoch(1, 1) +reportPartitionOffset(0, 1) +reportPartitionOffset(1, 1) + +makeSynchronousCall() + +verifyCommitHasntHappened(1) + } + + test("single epoch, all but one reader partition has reported an offset") { +setWriterPartitions(3) +setReaderPartitions(2) + +commitPartitionEpoch(0, 1) +commitPartitionEpoch(1, 1) +commitPartitionEpoch(2, 1) +reportPartitionOffset(0, 1) + +makeSynchronousCall() + +verifyCommitHasntHappened(1) --- End diff -- @tdas @jose-torres done --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #20983: [SPARK-23747][Structured Streaming] Add EpochCoor...
Github user tdas commented on a diff in the pull request: https://github.com/apache/spark/pull/20983#discussion_r180553748 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/streaming/continuous/EpochCoordinatorSuite.scala --- @@ -0,0 +1,225 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + *http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.sql.streaming.continuous + +import org.mockito.InOrder +import org.mockito.Matchers.{any, eq => eqTo} +import org.mockito.Mockito._ +import org.scalatest.BeforeAndAfterEach +import org.scalatest.mockito.MockitoSugar + +import org.apache.spark._ +import org.apache.spark.rpc.RpcEndpointRef +import org.apache.spark.sql.execution.streaming.continuous._ +import org.apache.spark.sql.sources.v2.reader.streaming.{ContinuousReader, PartitionOffset} +import org.apache.spark.sql.sources.v2.writer.WriterCommitMessage +import org.apache.spark.sql.sources.v2.writer.streaming.StreamWriter +import org.apache.spark.sql.test.SharedSparkSession + +class EpochCoordinatorSuite + extends SparkFunSuite +with SharedSparkSession +with MockitoSugar +with BeforeAndAfterEach { + + private var epochCoordinator: RpcEndpointRef = _ + + private var writer: StreamWriter = _ + private var query: ContinuousExecution = _ + private var orderVerifier: InOrder = _ + + override def beforeEach(): Unit = { +val reader = mock[ContinuousReader] +writer = mock[StreamWriter] +query = mock[ContinuousExecution] +orderVerifier = inOrder(writer, query) + +epochCoordinator + = EpochCoordinatorRef.create(writer, reader, query, "test", 1, spark, SparkEnv.get) + } + + override def afterEach(): Unit = { +SparkEnv.get.rpcEnv.stop(epochCoordinator) + } + + test("single epoch") { +setWriterPartitions(3) +setReaderPartitions(2) + +commitPartitionEpoch(0, 1) +commitPartitionEpoch(1, 1) +commitPartitionEpoch(2, 1) +reportPartitionOffset(0, 1) +reportPartitionOffset(1, 1) + +// Here and in subsequent tests this is called to make a synchronous call to EpochCoordinator +// so that mocks would have been acted upon by the time verification happens +makeSynchronousCall() + +verifyCommit(1) + } + + test("single epoch, all but one writer partition has committed") { +setWriterPartitions(3) +setReaderPartitions(2) + +commitPartitionEpoch(0, 1) +commitPartitionEpoch(1, 1) +reportPartitionOffset(0, 1) +reportPartitionOffset(1, 1) + +makeSynchronousCall() + +verifyCommitHasntHappened(1) + } + + test("single epoch, all but one reader partition has reported an offset") { +setWriterPartitions(3) +setReaderPartitions(2) + +commitPartitionEpoch(0, 1) +commitPartitionEpoch(1, 1) +commitPartitionEpoch(2, 1) +reportPartitionOffset(0, 1) + +makeSynchronousCall() + +verifyCommitHasntHappened(1) --- End diff -- +1 --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #20983: [SPARK-23747][Structured Streaming] Add EpochCoor...
Github user jose-torres commented on a diff in the pull request: https://github.com/apache/spark/pull/20983#discussion_r180490617 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/streaming/continuous/EpochCoordinatorSuite.scala --- @@ -0,0 +1,225 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + *http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.sql.streaming.continuous + +import org.mockito.InOrder +import org.mockito.Matchers.{any, eq => eqTo} +import org.mockito.Mockito._ +import org.scalatest.BeforeAndAfterEach +import org.scalatest.mockito.MockitoSugar + +import org.apache.spark._ +import org.apache.spark.rpc.RpcEndpointRef +import org.apache.spark.sql.execution.streaming.continuous._ +import org.apache.spark.sql.sources.v2.reader.streaming.{ContinuousReader, PartitionOffset} +import org.apache.spark.sql.sources.v2.writer.WriterCommitMessage +import org.apache.spark.sql.sources.v2.writer.streaming.StreamWriter +import org.apache.spark.sql.test.SharedSparkSession + +class EpochCoordinatorSuite + extends SparkFunSuite +with SharedSparkSession +with MockitoSugar +with BeforeAndAfterEach { + + private var epochCoordinator: RpcEndpointRef = _ + + private var writer: StreamWriter = _ + private var query: ContinuousExecution = _ + private var orderVerifier: InOrder = _ + + override def beforeEach(): Unit = { +val reader = mock[ContinuousReader] +writer = mock[StreamWriter] +query = mock[ContinuousExecution] +orderVerifier = inOrder(writer, query) + +epochCoordinator + = EpochCoordinatorRef.create(writer, reader, query, "test", 1, spark, SparkEnv.get) + } + + override def afterEach(): Unit = { +SparkEnv.get.rpcEnv.stop(epochCoordinator) + } + + test("single epoch") { +setWriterPartitions(3) +setReaderPartitions(2) + +commitPartitionEpoch(0, 1) +commitPartitionEpoch(1, 1) +commitPartitionEpoch(2, 1) +reportPartitionOffset(0, 1) +reportPartitionOffset(1, 1) + +// Here and in subsequent tests this is called to make a synchronous call to EpochCoordinator +// so that mocks would have been acted upon by the time verification happens +makeSynchronousCall() + +verifyCommit(1) + } + + test("single epoch, all but one writer partition has committed") { +setWriterPartitions(3) +setReaderPartitions(2) + +commitPartitionEpoch(0, 1) +commitPartitionEpoch(1, 1) +reportPartitionOffset(0, 1) +reportPartitionOffset(1, 1) + +makeSynchronousCall() + +verifyCommitHasntHappened(1) + } + + test("single epoch, all but one reader partition has reported an offset") { +setWriterPartitions(3) +setReaderPartitions(2) + +commitPartitionEpoch(0, 1) +commitPartitionEpoch(1, 1) +commitPartitionEpoch(2, 1) +reportPartitionOffset(0, 1) + +makeSynchronousCall() + +verifyCommitHasntHappened(1) --- End diff -- nit: maybe `verifyNoCommitFor` --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #20983: [SPARK-23747][Structured Streaming] Add EpochCoor...
Github user efimpoberezkin commented on a diff in the pull request: https://github.com/apache/spark/pull/20983#discussion_r180203421 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/streaming/continuous/EpochCoordinatorSuite.scala --- @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + *http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.sql.streaming.continuous + +import org.mockito.InOrder +import org.mockito.Matchers.{any, eq => eqTo} +import org.mockito.Mockito._ +import org.scalatest.BeforeAndAfterEach +import org.scalatest.mockito.MockitoSugar + +import org.apache.spark._ +import org.apache.spark.rpc.RpcEndpointRef +import org.apache.spark.sql.execution.streaming.continuous._ +import org.apache.spark.sql.sources.v2.reader.streaming.{ContinuousReader, PartitionOffset} +import org.apache.spark.sql.sources.v2.writer.WriterCommitMessage +import org.apache.spark.sql.sources.v2.writer.streaming.StreamWriter +import org.apache.spark.sql.test.SharedSparkSession + +class EpochCoordinatorSuite + extends SparkFunSuite +with SharedSparkSession +with MockitoSugar +with BeforeAndAfterEach { + + private var epochCoordinator: RpcEndpointRef = _ + + private var writer: StreamWriter = _ + private var query: ContinuousExecution = _ + private var orderVerifier: InOrder = _ + + private val startEpoch = 1L + + override def beforeEach(): Unit = { +val reader = mock[ContinuousReader] +writer = mock[StreamWriter] +query = mock[ContinuousExecution] +orderVerifier = inOrder(writer, query) + +epochCoordinator + = EpochCoordinatorRef.create(writer, reader, query, "test", startEpoch, spark, SparkEnv.get) + } + + override def afterEach(): Unit = { +SparkEnv.get.rpcEnv.stop(epochCoordinator) + } + + test("single epoch") { +setWriterPartitions(3) +setReaderPartitions(2) + +commitPartitionEpoch(0, startEpoch) +commitPartitionEpoch(1, startEpoch) +commitPartitionEpoch(2, startEpoch) +reportPartitionOffset(0, startEpoch) +reportPartitionOffset(1, startEpoch) + +// Here and in subsequent tests this is called to make a synchronous call to EpochCoordinator +// so that mocks would have been acted upon by the time verification happens +makeSynchronousCall() + +verifyCommit(startEpoch) + } + + test("consequent epochs, messages for epoch (k + 1) arrive after messages for epoch k") { +setWriterPartitions(2) +setReaderPartitions(2) + +val epochs = startEpoch to (startEpoch + 1) --- End diff -- I agree that it would be more readable, however the fact that we test for the start epoch first might be not as obvious then since it'd be hardcoded in before. Still pretty obvious though I guess.. and probably there will be no need to change start epoch in tests so hardcoding it is fine, and readability would increase. Will change this --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #20983: [SPARK-23747][Structured Streaming] Add EpochCoor...
Github user jose-torres commented on a diff in the pull request: https://github.com/apache/spark/pull/20983#discussion_r180179334 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/streaming/continuous/EpochCoordinatorSuite.scala --- @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + *http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.sql.streaming.continuous + +import org.mockito.InOrder +import org.mockito.Matchers.{any, eq => eqTo} +import org.mockito.Mockito._ +import org.scalatest.BeforeAndAfterEach +import org.scalatest.mockito.MockitoSugar + +import org.apache.spark._ +import org.apache.spark.rpc.RpcEndpointRef +import org.apache.spark.sql.execution.streaming.continuous._ +import org.apache.spark.sql.sources.v2.reader.streaming.{ContinuousReader, PartitionOffset} +import org.apache.spark.sql.sources.v2.writer.WriterCommitMessage +import org.apache.spark.sql.sources.v2.writer.streaming.StreamWriter +import org.apache.spark.sql.test.SharedSparkSession + +class EpochCoordinatorSuite + extends SparkFunSuite +with SharedSparkSession +with MockitoSugar +with BeforeAndAfterEach { + + private var epochCoordinator: RpcEndpointRef = _ + + private var writer: StreamWriter = _ + private var query: ContinuousExecution = _ + private var orderVerifier: InOrder = _ + + private val startEpoch = 1L + + override def beforeEach(): Unit = { +val reader = mock[ContinuousReader] +writer = mock[StreamWriter] +query = mock[ContinuousExecution] +orderVerifier = inOrder(writer, query) + +epochCoordinator + = EpochCoordinatorRef.create(writer, reader, query, "test", startEpoch, spark, SparkEnv.get) + } + + override def afterEach(): Unit = { +SparkEnv.get.rpcEnv.stop(epochCoordinator) + } + + test("single epoch") { +setWriterPartitions(3) +setReaderPartitions(2) + +commitPartitionEpoch(0, startEpoch) +commitPartitionEpoch(1, startEpoch) +commitPartitionEpoch(2, startEpoch) +reportPartitionOffset(0, startEpoch) +reportPartitionOffset(1, startEpoch) + +// Here and in subsequent tests this is called to make a synchronous call to EpochCoordinator +// so that mocks would have been acted upon by the time verification happens +makeSynchronousCall() + +verifyCommit(startEpoch) + } + + test("consequent epochs, messages for epoch (k + 1) arrive after messages for epoch k") { +setWriterPartitions(2) +setReaderPartitions(2) + +val epochs = startEpoch to (startEpoch + 1) --- End diff -- This is a personal preference thing, but I think it might be more readable to just use the raw numbers. Something like: commitPartitionEpoch(0, 1) commitPartitionEpoch(1, 1) [...] commitPartitionEpoch(0, 2) commitPartitionEpoch(1, 2) [...] verifyCommitsInOrderOf(1, 2) --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #20983: [SPARK-23747][Structured Streaming] Add EpochCoor...
Github user jose-torres commented on a diff in the pull request: https://github.com/apache/spark/pull/20983#discussion_r180178721 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/streaming/continuous/EpochCoordinatorSuite.scala --- @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + *http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.sql.streaming.continuous + +import org.mockito.InOrder +import org.mockito.Matchers.{any, eq => eqTo} +import org.mockito.Mockito._ +import org.scalatest.BeforeAndAfterEach +import org.scalatest.mockito.MockitoSugar + +import org.apache.spark._ +import org.apache.spark.rpc.RpcEndpointRef +import org.apache.spark.sql.execution.streaming.continuous._ +import org.apache.spark.sql.sources.v2.reader.streaming.{ContinuousReader, PartitionOffset} +import org.apache.spark.sql.sources.v2.writer.WriterCommitMessage +import org.apache.spark.sql.sources.v2.writer.streaming.StreamWriter +import org.apache.spark.sql.test.SharedSparkSession + +class EpochCoordinatorSuite + extends SparkFunSuite +with SharedSparkSession +with MockitoSugar +with BeforeAndAfterEach { + + private var epochCoordinator: RpcEndpointRef = _ + + private var writer: StreamWriter = _ + private var query: ContinuousExecution = _ + private var orderVerifier: InOrder = _ + + private val startEpoch = 1L + + override def beforeEach(): Unit = { +val reader = mock[ContinuousReader] +writer = mock[StreamWriter] +query = mock[ContinuousExecution] +orderVerifier = inOrder(writer, query) + +epochCoordinator + = EpochCoordinatorRef.create(writer, reader, query, "test", startEpoch, spark, SparkEnv.get) + } + + override def afterEach(): Unit = { +SparkEnv.get.rpcEnv.stop(epochCoordinator) + } + + test("single epoch") { +setWriterPartitions(3) +setReaderPartitions(2) + +commitPartitionEpoch(0, startEpoch) +commitPartitionEpoch(1, startEpoch) +commitPartitionEpoch(2, startEpoch) +reportPartitionOffset(0, startEpoch) +reportPartitionOffset(1, startEpoch) + +// Here and in subsequent tests this is called to make a synchronous call to EpochCoordinator +// so that mocks would have been acted upon by the time verification happens +makeSynchronousCall() + +verifyCommit(startEpoch) + } --- End diff -- I'd suggest adding test cases where all but one writer partition has committed, or all but one reader partition has reported an offset. In those cases we should verify that the StreamWriter and query commits haven't happened. --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #20983: [SPARK-23747][Structured Streaming] Add EpochCoor...
GitHub user efimpoberezkin opened a pull request: https://github.com/apache/spark/pull/20983 [SPARK-23747][Structured Streaming] Add EpochCoordinator unit tests ## What changes were proposed in this pull request? Unit tests for EpochCoordinator that test correct sequencing of committed epochs. Several tests are ignored since they test functionality implemented in SPARK-23503 which is not yet merged, otherwise they fail. You can merge this pull request into a Git repository by running: $ git pull https://github.com/efimpoberezkin/spark pr/EpochCoordinator-tests Alternatively you can review and apply these changes as the patch at: https://github.com/apache/spark/pull/20983.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #20983 commit b5cd06644a966c244368f02f03618d3319cb5090 Author: Efim PoberezkinDate: 2018-04-05T14:13:57Z [SPARK-23747][Structured Streaming] Added EpochCoordinator unit tests --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org