-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logging level check was added before logging and message construction. #114
Open
alexeykiselev
wants to merge
5
commits into
input-output-hk:devel
Choose a base branch
from
alexeykiselev:devel
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0e4a91e
Logging level check was added before logging and message construction.
alexeykiselev 95125ea
SerialVersionUIDs were set explicitly from 1.2.8 release.
alexeykiselev 1a4a294
Test data file removal after test was implemented.
alexeykiselev e69ca2a
Blacklisting of peers for a limited period of time was implemented.
alexeykiselev ef0059f
Constant naming fix.
alexeykiselev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
scorex-basics/src/main/scala/scorex/account/PublicKeyAccount.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package scorex.account | ||
|
||
|
||
@SerialVersionUID(-5511437096393374460L) | ||
class PublicKeyAccount(val publicKey: Array[Byte]) extends Account(Account.fromPublicKey(publicKey)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 44 additions & 2 deletions
46
scorex-basics/src/main/scala/scorex/utils/ScorexLogging.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,49 @@ | ||
package scorex.utils | ||
|
||
import org.slf4j.LoggerFactory | ||
import org.slf4j.{Logger, LoggerFactory} | ||
|
||
case class LoggerFacade(logger: Logger) { | ||
def trace(message: => String): Unit = { | ||
if (logger.isTraceEnabled) | ||
logger.trace(message) | ||
} | ||
|
||
def debug(message: => String): Unit = { | ||
if (logger.isDebugEnabled) | ||
logger.debug(message) | ||
} | ||
|
||
def info(message: => String): Unit = { | ||
if (logger.isInfoEnabled) | ||
logger.info(message) | ||
} | ||
|
||
def info(message: => String, throwable: Throwable): Unit = { | ||
if (logger.isInfoEnabled) | ||
logger.info(message, throwable) | ||
} | ||
|
||
def warn(message: => String): Unit = { | ||
if (logger.isWarnEnabled) | ||
logger.warn(message) | ||
} | ||
|
||
def warn(message: => String, throwable: Throwable): Unit = { | ||
if (logger.isWarnEnabled) | ||
logger.warn(message, throwable) | ||
} | ||
|
||
def error(message: => String): Unit = { | ||
if (logger.isErrorEnabled) | ||
logger.error(message) | ||
} | ||
|
||
def error(message: => String, throwable: Throwable): Unit = { | ||
if (logger.isErrorEnabled) | ||
logger.error(message, throwable) | ||
} | ||
} | ||
|
||
trait ScorexLogging { | ||
protected def log = LoggerFactory.getLogger(this.getClass) | ||
protected def log = LoggerFacade(LoggerFactory.getLogger(this.getClass)) | ||
} |
106 changes: 106 additions & 0 deletions
106
scorex-basics/src/test/scala/scorex/network/BlacklistParallelSpecification.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package scorex.network | ||
|
||
import java.net.{InetAddress, InetSocketAddress} | ||
|
||
import org.scalatest.{FeatureSpec, GivenWhenThen, ParallelTestExecution} | ||
import play.api.libs.json.{JsObject, Json} | ||
import scorex.network.peer.{PeerDatabaseImpl, PeerInfo} | ||
import scorex.settings.Settings | ||
|
||
class BlacklistParallelSpecification extends FeatureSpec with GivenWhenThen with ParallelTestExecution { | ||
|
||
object TestSettings extends Settings { | ||
override lazy val settingsJSON: JsObject = Json.obj() | ||
override val filename: String = "" | ||
override lazy val blacklistResidenceTimeMilliseconds = 1000L | ||
} | ||
|
||
info("As a Peer") | ||
info("I want to blacklist other peers for certain time") | ||
info("So I can give them another chance after") | ||
|
||
feature("Blacklist") { | ||
scenario("Peer blacklist another peer") { | ||
|
||
Given("Peer database is empty") | ||
val peerDatabase = new PeerDatabaseImpl(TestSettings, None) | ||
assert(peerDatabase.knownPeers(false).isEmpty) | ||
assert(peerDatabase.blacklistedPeers().isEmpty) | ||
|
||
When("Peer adds another peer to whitelist") | ||
val anotherPeer = new PeerInfo(System.currentTimeMillis) | ||
val port: Int = 1234 | ||
val address = new InetSocketAddress(InetAddress.getByName("ya.ru"), port) | ||
peerDatabase.addOrUpdateKnownPeer(address, anotherPeer) | ||
assert(peerDatabase.knownPeers(false).contains(address)) | ||
assert(!peerDatabase.blacklistedPeers().contains(address.getHostName)) | ||
|
||
And("Peer blacklists another peer") | ||
peerDatabase.blacklistPeer(address) | ||
assert(peerDatabase.isBlacklisted(address)) | ||
assert(peerDatabase.blacklistedPeers().contains(address.getHostName)) | ||
assert(!peerDatabase.knownPeers(false).contains(address)) | ||
|
||
And("Peer waits for some time") | ||
Thread.sleep(TestSettings.blacklistResidenceTimeMilliseconds) | ||
|
||
Then("Another peer disappear from blacklist") | ||
assert(!peerDatabase.isBlacklisted(address)) | ||
|
||
And("Another peer still not in whitelist") | ||
assert(!peerDatabase.knownPeers(false).contains(address)) | ||
} | ||
|
||
scenario("Peer blacklist few peers") { | ||
|
||
Given("Peer database is empty") | ||
val peerDatabase = new PeerDatabaseImpl(TestSettings, None) | ||
assert(peerDatabase.knownPeers(false).isEmpty) | ||
assert(peerDatabase.blacklistedPeers().isEmpty) | ||
|
||
When("Peer adds other peers") | ||
val anotherPeer = new PeerInfo(System.currentTimeMillis) | ||
val port: Int = 1234 | ||
val address1 = new InetSocketAddress(InetAddress.getByName("bing.com"), port) | ||
val address2 = new InetSocketAddress(InetAddress.getByName("google.com"), port) | ||
val address3 = new InetSocketAddress(InetAddress.getByName("yandex.ru"), port) | ||
peerDatabase.addOrUpdateKnownPeer(address1, anotherPeer) | ||
peerDatabase.addOrUpdateKnownPeer(address2, anotherPeer) | ||
peerDatabase.addOrUpdateKnownPeer(address3, anotherPeer) | ||
assert(!peerDatabase.isBlacklisted(address1)) | ||
assert(!peerDatabase.isBlacklisted(address2)) | ||
assert(!peerDatabase.isBlacklisted(address3)) | ||
|
||
And("Peer blacklists other peers") | ||
peerDatabase.blacklistPeer(address1) | ||
peerDatabase.blacklistPeer(address2) | ||
peerDatabase.blacklistPeer(address3) | ||
assert(peerDatabase.isBlacklisted(address1)) | ||
assert(peerDatabase.isBlacklisted(address2)) | ||
assert(peerDatabase.isBlacklisted(address3)) | ||
|
||
And("Peer waits half period") | ||
Thread.sleep(TestSettings.blacklistResidenceTimeMilliseconds / 2) | ||
|
||
And("Adds one peer to blacklist one more time") | ||
peerDatabase.blacklistPeer(address2) | ||
|
||
And("Waits another half of period") | ||
Thread.sleep(TestSettings.blacklistResidenceTimeMilliseconds / 2) | ||
|
||
Then("Two peers disappear from blacklist") | ||
assert(!peerDatabase.isBlacklisted(address1)) | ||
assert(peerDatabase.isBlacklisted(address2)) | ||
assert(!peerDatabase.isBlacklisted(address3)) | ||
|
||
And("Then waits another half of period") | ||
Thread.sleep(TestSettings.blacklistResidenceTimeMilliseconds / 2) | ||
|
||
And("All peers not in blacklist") | ||
assert(!peerDatabase.isBlacklisted(address1)) | ||
assert(!peerDatabase.isBlacklisted(address2)) | ||
assert(!peerDatabase.isBlacklisted(address3)) | ||
} | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
scorex-basics/src/test/scala/scorex/network/BlacklistSpecification.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package scorex.network | ||
|
||
import java.net.{InetAddress, InetSocketAddress} | ||
|
||
import org.scalatest.{FeatureSpec, GivenWhenThen} | ||
import play.api.libs.json.{JsObject, Json} | ||
import scorex.network.peer.{PeerDatabaseImpl, PeerInfo} | ||
import scorex.settings.Settings | ||
|
||
class BlacklistSpecification extends FeatureSpec with GivenWhenThen { | ||
|
||
object TestSettings extends Settings { | ||
override lazy val settingsJSON: JsObject = Json.obj() | ||
override val filename: String = "" | ||
override lazy val blacklistResidenceTimeMilliseconds = 1000L | ||
} | ||
|
||
info("As a Peer") | ||
info("I want to blacklist other peers for certain time") | ||
info("So I can give them another chance after") | ||
|
||
feature("Blacklist") { | ||
scenario("Peer blacklist another peer") { | ||
|
||
Given("Peer database is empty") | ||
val peerDatabase = new PeerDatabaseImpl(TestSettings, None) | ||
assert(peerDatabase.knownPeers(false).isEmpty) | ||
assert(peerDatabase.blacklistedPeers().isEmpty) | ||
|
||
When("Peer adds another peer to whitelist") | ||
val anotherPeer = new PeerInfo(System.currentTimeMillis) | ||
val port: Int = 1234 | ||
val address = new InetSocketAddress(InetAddress.getByName("localhost"), port) | ||
peerDatabase.addOrUpdateKnownPeer(address, anotherPeer) | ||
assert(peerDatabase.knownPeers(false).contains(address)) | ||
assert(!peerDatabase.blacklistedPeers().contains(address.getHostName)) | ||
|
||
And("Peer blacklists another peer") | ||
peerDatabase.blacklistPeer(address) | ||
assert(peerDatabase.isBlacklisted(address)) | ||
assert(peerDatabase.blacklistedPeers().contains(address.getHostName)) | ||
assert(!peerDatabase.knownPeers(false).contains(address)) | ||
|
||
And("Peer waits for some time") | ||
Thread.sleep(TestSettings.blacklistResidenceTimeMilliseconds) | ||
|
||
Then("Another peer disappear from blacklist") | ||
assert(!peerDatabase.isBlacklisted(address)) | ||
|
||
And("Another peer still not in whitelist") | ||
assert(!peerDatabase.knownPeers(false).contains(address)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
scorex-transaction/src/main/scala/scorex/transaction/state/database/state/AccState.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
package scorex.transaction.state.database.state | ||
|
||
@SerialVersionUID(5655285204140981736L) | ||
case class AccState(balance: Long) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use such approach, use BytesSerializable to serialize Address, it's a mistake to put Java object to db