-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Protect against doing requests for snapshots that are over 400KB.
Sources: https://zaccharles.medium.com/calculating-a-dynamodb-items-size-and-consumed-capacity-d1728942eb7c https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/CapacityUnitCalculations.html
- Loading branch information
Showing
4 changed files
with
92 additions
and
1 deletion.
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
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
62 changes: 62 additions & 0 deletions
62
src/test/scala/org/apache/pekko/persistence/dynamodb/snapshot/SnapshotTooBigSpec.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,62 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* license agreements; and to You under the Apache License, version 2.0: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This file is part of the Apache Pekko project, which was derived from Akka. | ||
*/ | ||
|
||
package org.apache.pekko.persistence.dynamodb.snapshot | ||
|
||
import com.typesafe.config.ConfigFactory | ||
import org.apache.pekko.actor.ActorSystem | ||
import org.apache.pekko.testkit._ | ||
import org.apache.pekko.persistence._ | ||
import org.apache.pekko.persistence.SnapshotProtocol._ | ||
import org.apache.pekko.persistence.dynamodb.IntegSpec | ||
import org.scalatest._ | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpecLike | ||
|
||
class SnapshotTooBigSpec extends TestKit(ActorSystem("SnapshotTooBigSpec")) | ||
with AnyWordSpecLike | ||
with BeforeAndAfterAll | ||
with BeforeAndAfterEach | ||
with Matchers | ||
with IntegSpec | ||
with DynamoDBUtils { | ||
|
||
override def beforeAll(): Unit = { | ||
super.beforeAll() | ||
this.ensureSnapshotTableExists() | ||
} | ||
|
||
override protected def beforeEach(): Unit = { | ||
super.beforeEach() | ||
senderProbe = TestProbe() | ||
} | ||
|
||
override def afterAll(): Unit = { | ||
super.afterAll() | ||
client.shutdown() | ||
} | ||
|
||
private var senderProbe: TestProbe = _ | ||
val persistenceId = "SnapshotTooBigSpec" | ||
val snapshotStore = Persistence(system).snapshotStoreFor("") | ||
|
||
"DynamoDB snapshot too big spec" must { | ||
|
||
"1 reject a snapshot that is over 400 KB compressed." in { | ||
// Expect 1 MB of random data to exceed 400KB compressed. | ||
val bytes = new Array[Byte](1 << 20) | ||
scala.util.Random.nextBytes(bytes) | ||
val metadata = SnapshotMetadata.apply(persistenceId, 1, 0) | ||
snapshotStore.tell(SaveSnapshot(metadata, bytes), senderProbe.ref) | ||
val rej = senderProbe.expectMsgType[SaveSnapshotFailure] | ||
rej.cause shouldBe a[DynamoDBSnapshotRejection] | ||
rej.cause.getMessage().startsWith("MaxItemSize exceeded") shouldBe true | ||
} | ||
} | ||
} |