Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class KafkaProducerActorImpl(
flushMessagesScheduledTask.cancel()
checkKTableLagScheduledTask.cancel()
clearExpiredTrackersScheduledTask.cancel()
kafkaPublisher.close()
super.postStop()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import surge.health.domain.EmittableHealthSignal
import surge.internal.akka.cluster.ActorSystemHostAwareness
import surge.internal.akka.kafka.{ KafkaConsumerPartitionAssignmentTracker, KafkaConsumerStateTrackingActor }
import surge.internal.health.{ HealthCheck, HealthCheckStatus }
import surge.internal.kafka.KafkaProducerActorImpl.{ KTableProgressUpdate, PublishTrackerStateManager, SenderWithTrackingId }
import surge.internal.kafka.KafkaProducerActorImpl.{ KTableProgressUpdate, PublishTrackerStateManager, SenderWithTrackingId, ShutdownProducer }
import surge.kafka._
import surge.internal.health.HealthyActor.GetHealth
import surge.kafka.streams.ExpectedTestException
Expand Down Expand Up @@ -678,6 +678,21 @@ class KafkaProducerActorImplSpec
probe.expectMsgClass(classOf[PublishSuccess])
verify(mockProducerFenceOnCommit).putRecords(records(testMessages2))
}

"Close Kafka Producer on Shutdown" in {
val probe = TestProbe()
val mockPartitionTracker = mock[KafkaConsumerPartitionAssignmentTracker]
val mockProducer = mock[GenericKafkaProducer[String, Array[Byte]]]

val mockLagChecker = mockKTableLagChecker(assignedPartition, 100L, 100L)
val producerActorToShutdown =
testProducerActor(assignedPartition, mockProducer, mockLagChecker, new PublishTrackerStateManager(), mockPartitionTracker)

// Send Shutdown Command
probe.send(producerActorToShutdown, ShutdownProducer)

verify(mockProducer, Mockito.timeout(1000).atLeast(1)).close()
}
}

"KafkaProducerActorState" should {
Expand Down