adixitconfluent commented on code in PR #16263:
URL: https://github.com/apache/kafka/pull/16263#discussion_r1637556905


##########
core/src/test/java/kafka/server/share/SharePartitionManagerTest.java:
##########
@@ -0,0 +1,916 @@
+/*
+ * 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 kafka.server.share;
+
+import kafka.server.ReplicaManager;
+import org.apache.kafka.common.TopicIdPartition;
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.Uuid;
+import org.apache.kafka.common.errors.InvalidRequestException;
+import org.apache.kafka.common.errors.InvalidShareSessionEpochException;
+import org.apache.kafka.common.errors.ShareSessionNotFoundException;
+import org.apache.kafka.common.message.ShareFetchResponseData;
+import org.apache.kafka.common.protocol.ApiKeys;
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.common.protocol.ObjectSerializationCache;
+import org.apache.kafka.common.requests.ShareFetchMetadata;
+import org.apache.kafka.common.requests.ShareFetchRequest;
+import org.apache.kafka.common.requests.ShareFetchResponse;
+import org.apache.kafka.common.utils.MockTime;
+import org.apache.kafka.common.utils.Time;
+import org.apache.kafka.server.share.ShareSessionCache;
+import org.apache.kafka.server.share.ShareSessionKey;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Collections;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.LinkedHashMap;
+import java.util.Set;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+
+@Timeout(120)
+public class SharePartitionManagerTest {
+
+    private static final int RECORD_LOCK_DURATION_MS = 30000;
+    private static final int MAX_DELIVERY_COUNT = 5;
+    private static final short MAX_IN_FLIGHT_MESSAGES = 200;
+
+    private final List<TopicIdPartition> emptyPartList = 
Collections.unmodifiableList(new ArrayList<>());
+
+    @Test
+    public void testNewContextReturnsFinalContext() {
+        SharePartitionManager sharePartitionManager = 
SharePartitionManagerBuilder.builder().build();
+
+        ShareFetchMetadata newReqMetadata = new 
ShareFetchMetadata(Uuid.ZERO_UUID, -1);
+        ShareFetchContext shareFetchContext = 
sharePartitionManager.newContext("grp", new HashMap<>(), new ArrayList<>(), 
newReqMetadata);
+        assertEquals(shareFetchContext.getClass(), 
SharePartitionManager.FinalContext.class);
+
+        // If the final fetch request has topics to add, it should fail as an 
invalid request
+        Uuid topicId = Uuid.randomUuid();
+        Map<TopicIdPartition, ShareFetchRequest.SharePartitionData> 
shareFetchData = new HashMap<>();
+        shareFetchData.put(new TopicIdPartition(topicId, new 
TopicPartition("foo", 0)),
+                new ShareFetchRequest.SharePartitionData(topicId, 4000));
+        assertThrows(InvalidRequestException.class,
+                () -> sharePartitionManager.newContext("grp", shareFetchData, 
new ArrayList<>(), new ShareFetchMetadata(Uuid.ZERO_UUID, -1)));
+
+        // shareFetchData is not empty, but the maxBytes of topic partition is 
0, which means this is added only for acknowledgements.
+        // New context should be created successfully
+        shareFetchData.clear();
+        shareFetchData.put(new TopicIdPartition(topicId, new 
TopicPartition("foo", 0)),
+                new ShareFetchRequest.SharePartitionData(topicId, 0));
+        shareFetchContext = sharePartitionManager.newContext("grp", 
shareFetchData, new ArrayList<>(), newReqMetadata);
+        assertEquals(shareFetchContext.getClass(), 
SharePartitionManager.FinalContext.class);
+    }
+
+    @Test
+    public void testNewContext() {

Review Comment:
   Yes, I can only segregate out one of the cases from the following test 
because for others I need them to work one after the other



-- 
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.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to