You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@samza.apache.org by GitBox <gi...@apache.org> on 2019/05/06 16:44:51 UTC

[GitHub] [samza] rmatharu commented on a change in pull request #1008: SAMZA-2174: Throw a record too large exception for oversized records in changelog

rmatharu commented on a change in pull request #1008: SAMZA-2174: Throw a record too large exception for oversized records in changelog
URL: https://github.com/apache/samza/pull/1008#discussion_r281264264
 
 

 ##########
 File path: samza-kv/src/test/scala/org/apache/samza/storage/kv/TestLoggedStore.scala
 ##########
 @@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.samza.storage.kv
+
+import java.util._
+
+import org.apache.samza.config.Config
+import org.apache.samza.metrics.Counter
+import org.apache.samza.system.SystemStreamPartition
+import org.apache.samza.task.MessageCollector
+import org.apache.samza.{Partition, SamzaException}
+import org.junit.{Before, Test}
+import org.mockito.Matchers
+import org.mockito.Mockito._
+
+
+class TestLoggedStore {
+
+  val store = mock(classOf[KeyValueStore[Array[Byte], Array[Byte]]])
+  val storeName = "testStore"
+  val storeConfig = mock(classOf[Config])
+  val systemStreamPartition = mock(classOf[SystemStreamPartition])
+  val collector = mock(classOf[MessageCollector])
+  val metrics = mock(classOf[LoggedStoreMetrics])
+  val maxMessageSize = 1024
+  val counter = mock(classOf[Counter])
+
+  @Before
+  def setup: Unit = {
+    when(systemStreamPartition.getPartition).thenReturn(new Partition(1))
+    when(storeConfig.getInt(Matchers.eq("changelog.max.message.size.bytes"), Matchers.any())).thenReturn(maxMessageSize)
+    when(metrics.puts).thenReturn(counter)
+    when(counter.inc()).thenReturn(1)
+    doNothing().when(collector).send(Matchers.any())
+    doNothing().when(store).put(Matchers.any(), Matchers.any())
+    doNothing().when(store).putAll(Matchers.any())
+  }
+
+  @Test
+  def testLargeMessagePut = {
+    val safeLoggedStore = new LoggedStore(store, storeName, storeConfig, systemStreamPartition, collector, metrics)
+
+    val key1 = new Array[Byte](16)
+    val smallMessage = new Array[Byte](32)
+    safeLoggedStore.put(key1, smallMessage)
+    verify(store, times(1)).put(Matchers.eq(key1), Matchers.eq(smallMessage))
+
+    val key2 = new Array[Byte](16)
+    val largeMessage = new Array[Byte](1025)
+    try {
+      safeLoggedStore.put(key2, largeMessage)
+    } catch {
+      case e: SamzaException =>
+        verify(store, times(0)).put(Matchers.eq(key2), Matchers.eq(largeMessage))
+    }
+  }
+
+  @Test
+  def testSmallMessagePutAllSuccess = {
 
 Review comment:
   Maybe add tests with sample-messages serialized using serializers in org.apache.samza.serializers.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services