Skip to content

Commit

Permalink
DEX-958 Prepare release 2.2.4 (#401)
Browse files Browse the repository at this point in the history
The right Diff for WsAddressChanges
  • Loading branch information
vsuharnikov authored Nov 2, 2020
1 parent 50b117b commit 5e61d64
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
package com.wavesplatform.dex.it.cache

import java.util.concurrent.locks.ReentrantReadWriteLock

class CachedData[T <: AnyRef](getData: => T) {

private val lock = new ReentrantReadWriteLock()
private val read = lock.readLock()
private val write = lock.writeLock()

private var cached = Option.empty[T]

def get(): T =
try {
read.lock()
cached match {
case Some(x) => x
case None =>
val r = getData
cached = Some(r)
r
}
} finally read.unlock()

def invalidate(): Unit =
try {
write.lock()
cached = None
} finally write.unlock()
@volatile private var cached = Option.empty[T]

def get(): T = synchronized {
cached match {
case Some(x) => x
case None =>
val r = getData
cached = Some(r)
r
}
}

def invalidate(): Unit = synchronized {
cached = None
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ abstract class BaseContainer(protected val baseContainerPath: String, private va
}

def connectToNetwork(): Unit = {
invalidateCaches()

dockerClient
.connectToNetworkCmd()
.withContainerId(underlying.containerId)
Expand All @@ -147,11 +145,33 @@ abstract class BaseContainer(protected val baseContainerPath: String, private va
)
.exec()

Iterator
.continually {
Thread.sleep(1000)
dockerClient.inspectContainerCmd(underlying.containerId).exec().getNetworkSettings
}
.zipWithIndex
.find { case (ns, attempt) =>
ns.getNetworks.asScala.exists(_._2.getNetworkID == underlying.network.getId) || attempt == 20
}
.fold(log.warn(s"Can't start ${underlying.containerId}"))(_ => ())

invalidateCaches()
waitReady()
}

override def start(): Unit = {
Option(underlying.containerId).fold(super.start())(_ => sendStartCmd())

Iterator
.continually {
Thread.sleep(1000)
dockerClient.inspectContainerCmd(underlying.containerId).exec().getState
}
.zipWithIndex
.find { case (state, attempt) => state.getRunning || attempt == 20 }
.fold(log.warn(s"Can't start ${underlying.containerId}"))(_ => ())

invalidateCaches()
waitReady()
}
Expand Down
5 changes: 4 additions & 1 deletion dex-it/src/test/scala/com/wavesplatform/it/WsSuiteBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.softwaremill.diffx.{Derived, Diff}
import com.wavesplatform.dex.api.ws.connection.WsConnection
import com.wavesplatform.dex.api.ws.connection.WsConnection.WsRawMessage
import com.wavesplatform.dex.api.ws.entities.WsFullOrder
import com.wavesplatform.dex.api.ws.protocol.{WsError, WsPingOrPong, WsServerMessage}
import com.wavesplatform.dex.api.ws.protocol.{WsAddressChanges, WsError, WsPingOrPong, WsServerMessage}
import com.wavesplatform.dex.it.api.websockets.HasWebSockets

import scala.concurrent.duration.{DurationInt, FiniteDuration}
Expand All @@ -15,6 +15,9 @@ trait WsSuiteBase extends MatcherSuiteBase with HasWebSockets {

implicit protected val wsErrorDiff: Diff[WsError] = Derived[Diff[WsError]].ignore[WsError, Long](_.timestamp)

implicit protected val wsAddressChangesDiff: Diff[WsAddressChanges] =
Derived[Diff[WsAddressChanges]].ignore[WsAddressChanges, Long](_.timestamp)

implicit protected val wsCompleteOrderDiff: Diff[WsFullOrder] =
Derived[Diff[WsFullOrder]].ignore[WsFullOrder, Long](_.timestamp).ignore[WsFullOrder, Long](_.eventTimestamp)

Expand Down

0 comments on commit 5e61d64

Please sign in to comment.