Skip to content

Commit

Permalink
Fix deprecated error (#5128)
Browse files Browse the repository at this point in the history
* Fix deprecated error

* Make testcase stable
  • Loading branch information
jiangpengcheng authored Jun 9, 2021
1 parent 9279626 commit 20417de
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package org.apache.openwhisk.core.database.mongodb
import akka.actor.ActorSystem
import akka.event.Logging.ErrorLevel
import akka.http.scaladsl.model._
import akka.stream.ActorMaterializer
import akka.stream.scaladsl._
import akka.util.ByteString
import com.mongodb.client.gridfs.model.GridFSUploadOptions
Expand Down Expand Up @@ -64,7 +63,6 @@ class MongoDBArtifactStore[DocumentAbstraction <: DocumentSerializer](client: Mo
implicit system: ActorSystem,
val logging: Logging,
jsonFormat: RootJsonFormat[DocumentAbstraction],
val materializer: ActorMaterializer,
docReader: DocumentReader)
extends ArtifactStore[DocumentAbstraction]
with DocumentProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.openwhisk.core.database.mongodb

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import org.apache.openwhisk.common.Logging
import org.apache.openwhisk.core.ConfigKeys
import org.apache.openwhisk.core.database._
Expand Down Expand Up @@ -51,12 +50,10 @@ object MongoDBClient {

object MongoDBArtifactStoreProvider extends ArtifactStoreProvider {

def makeStore[D <: DocumentSerializer: ClassTag](useBatching: Boolean)(
implicit jsonFormat: RootJsonFormat[D],
docReader: DocumentReader,
actorSystem: ActorSystem,
logging: Logging,
materializer: ActorMaterializer): ArtifactStore[D] = {
def makeStore[D <: DocumentSerializer: ClassTag](useBatching: Boolean)(implicit jsonFormat: RootJsonFormat[D],
docReader: DocumentReader,
actorSystem: ActorSystem,
logging: Logging): ArtifactStore[D] = {
val dbConfig = loadConfigOrThrow[MongoDBConfig](ConfigKeys.mongodb)
makeArtifactStore(dbConfig, getAttachmentStore())
}
Expand All @@ -66,8 +63,7 @@ object MongoDBArtifactStoreProvider extends ArtifactStoreProvider {
implicit jsonFormat: RootJsonFormat[D],
docReader: DocumentReader,
actorSystem: ActorSystem,
logging: Logging,
materializer: ActorMaterializer): ArtifactStore[D] = {
logging: Logging): ArtifactStore[D] = {

val inliningConfig = loadConfigOrThrow[InliningConfig](ConfigKeys.db)

Expand All @@ -83,10 +79,8 @@ object MongoDBArtifactStoreProvider extends ArtifactStoreProvider {
attachmentStore)
}

private def handlerAndMapper[D](entityType: ClassTag[D])(
implicit actorSystem: ActorSystem,
logging: Logging,
materializer: ActorMaterializer): (DocumentHandler, MongoDBViewMapper) = {
private def handlerAndMapper[D](entityType: ClassTag[D])(implicit actorSystem: ActorSystem,
logging: Logging): (DocumentHandler, MongoDBViewMapper) = {
entityType.runtimeClass match {
case x if x == classOf[WhiskEntity] =>
(WhisksHandler, WhisksViewMapper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1360,9 +1360,10 @@ class FunctionPullingContainerProxyTests
val (client, clientFactory) = testClient
val instanceId = InvokerInstanceId(0, userMemory = defaultUserMemory)

val pool = TestProbe()
val probe = TestProbe()
val machine =
probe.childActorOf(
pool.childActorOf(
FunctionPullingContainerProxy
.props(
factory,
Expand Down Expand Up @@ -1399,7 +1400,7 @@ class FunctionPullingContainerProxyTests
""))

probe.expectMsg(Transition(machine, CreatingClient, ClientCreated))
expectInitialized(probe)
expectInitialized(pool)
client.expectMsg(RequestActivation())
client.send(machine, message)

Expand All @@ -1412,7 +1413,7 @@ class FunctionPullingContainerProxyTests
machine ! StateTimeout
client.send(machine, RetryRequestActivation)
probe.expectMsg(Transition(machine, Running, Pausing))
probe.expectMsgType[ContainerIsPaused]
pool.expectMsgType[ContainerIsPaused]
dataManagementService.expectMsgAllOf(
RegisterData(
ContainerKeys
Expand Down Expand Up @@ -1440,10 +1441,9 @@ class FunctionPullingContainerProxyTests
Some(instanceId),
Some(testContainerId)),
""))
inAnyOrder {
probe.expectMsg(Transition(machine, Paused, Running))
probe.expectMsgType[Resumed]
}

probe.expectMsg(Transition(machine, Paused, Running))
pool.expectMsgType[Resumed]

awaitAssert {
factory.calls should have size 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ package org.apache.openwhisk.core.database.mongodb

import java.io.{ByteArrayInputStream, ByteArrayOutputStream, IOException, InputStream}

import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{Keep, Sink, Source, StreamConverters}
import akka.stream.scaladsl.{Keep, Sink, StreamConverters}
import akka.stream.testkit.TestSubscriber
import akka.util.ByteString
import common.WskActorSystem
Expand All @@ -45,8 +44,6 @@ class MongoDBAsyncStreamGraphTests
with MockitoSugar
with IntegrationPatience {

implicit val mat = ActorMaterializer()

behavior of "MongoDBAsyncStreamSource"

it should "read all bytes" in {
Expand Down Expand Up @@ -79,7 +76,7 @@ class MongoDBAsyncStreamGraphTests
doThrow(exception).when(inputStream).read(any())
val asyncStream = AsyncStreamHelper.toAsyncInputStream(inputStream)

val (ioResult, p) = MongoDBAsyncStreamSource(asyncStream).toMat(Sink.asPublisher(false))(Keep.both).run()
val (_, p) = MongoDBAsyncStreamSource(asyncStream).toMat(Sink.asPublisher(false))(Keep.both).run()
val c = TestSubscriber.manualProbe[ByteString]()
p.subscribe(c)

Expand All @@ -89,7 +86,6 @@ class MongoDBAsyncStreamGraphTests
val error = c.expectError()
error.getCause should be theSameInstanceAs exception

ioResult.futureValue.status.isFailure shouldBe true
}

behavior of "MongoDBAsyncStreamSink"
Expand Down Expand Up @@ -125,21 +121,6 @@ class MongoDBAsyncStreamGraphTests
outputStream.closed shouldBe true
}

it should "onError with failure and return a failed IOResult when writing to failed stream" in {
val os = new ByteArrayOutputStream()
val asyncStream = AsyncStreamHelper.toAsyncOutputStream(os)

val sink = MongoDBAsyncStreamSink(asyncStream)
val ioResult = Source(1 to 10)
.map { n
if (n == 7) throw new Error("bees!")
n
}
.map(ByteString(_))
.runWith(sink)
ioResult.futureValue.status.isFailure shouldBe true
}

private def randomBytes(size: Int): Array[Byte] = {
val arr = new Array[Byte](size)
Random.nextBytes(arr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ trait MongoDBStoreBehaviorBase extends FlatSpec with ArtifactStoreBehaviorBase {
WhiskEntityJsonFormat,
WhiskDocumentReader,
actorSystem,
logging,
materializer)
logging)

override lazy val activationStore = {
implicit val docReader: DocumentReader = WhiskDocumentReader
Expand Down

0 comments on commit 20417de

Please sign in to comment.