Copilot commented on code in PR #11199:
URL: https://github.com/apache/gravitino/pull/11199#discussion_r3297903060
##########
core/src/test/java/org/apache/gravitino/audit/v2/TestSimpleAuditLogV2.java:
##########
@@ -71,6 +76,129 @@ public void testOutputContainsAllCoreFields() {
Assertions.assertTrue(output.contains("SUCCESS"));
}
+ // ---- list event tests ----
+ @Test
+ public void testListTableEventFormat() {
+ Namespace namespace = Namespace.of("metalake", "catalog", "schema");
+ ListTableEvent event = new ListTableEvent("alice", namespace, 5);
+ SimpleAuditLogV2 log = new SimpleAuditLogV2(event);
+
+ Assertions.assertEquals(OperationType.LIST_TABLE, log.operationType());
+ Assertions.assertEquals(OperationStatus.SUCCESS, log.operationStatus());
+ Assertions.assertEquals("metalake.catalog.schema", log.identifier());
+ Assertions.assertEquals("alice", log.user());
+
+ String output = log.toString();
+ String[] fields = output.split("\t", -1);
+ Assertions.assertEquals(8, fields.length);
+ Assertions.assertTrue(
+ fields[0].matches("\\[\\d{4}-\\d{2}-\\d{2}
\\d{2}:\\d{2}:\\d{2}\\.\\d{3}\\]"));
+ Assertions.assertEquals("alice", fields[1]);
+ Assertions.assertEquals("LIST_TABLE", fields[2]);
+ Assertions.assertEquals("metalake.catalog.schema", fields[3]);
+ Assertions.assertEquals("SUCCESS", fields[4]);
+ Assertions.assertEquals("GRAVITINO_SERVER", fields[5]);
+ Assertions.assertEquals("unknown", fields[6]); // no RequestContext set in
tests
+ Assertions.assertEquals("{count=5}", fields[7]); // count surfaced in last
field
+ }
+
+ @Test
+ public void testListMetalakeEventNullIdentifier() {
+ ListMetalakeEvent event = new ListMetalakeEvent("bob", 3);
+ SimpleAuditLogV2 log = new SimpleAuditLogV2(event);
+
+ Assertions.assertNull(log.identifier());
+ Assertions.assertEquals(OperationType.LIST_METALAKE, log.operationType());
+
+ // toString() must not throw and must have 8 fields with count in last
field.
+ String[] fields = log.toString().split("\t", -1);
+ Assertions.assertEquals(8, fields.length);
+ Assertions.assertEquals("bob", fields[1]);
+ Assertions.assertEquals("LIST_METALAKE", fields[2]);
+ Assertions.assertEquals("null", fields[3]);
+ Assertions.assertEquals("{count=3}", fields[7]);
+ }
+
+ @Test
+ public void testListCatalogEventFormat() {
+ Namespace namespace = Namespace.of("metalake");
+ ListCatalogEvent event = new ListCatalogEvent("carol", namespace, 2);
+ SimpleAuditLogV2 log = new SimpleAuditLogV2(event);
+
+ Assertions.assertEquals("metalake", log.identifier());
+ Assertions.assertEquals(OperationType.LIST_CATALOG, log.operationType());
+
+ String[] fields = log.toString().split("\t", -1);
+ Assertions.assertEquals("LIST_CATALOG", fields[2]);
+ Assertions.assertEquals("metalake", fields[3]);
+ Assertions.assertEquals("{count=2}", fields[7]);
+ }
+
+ @Test
+ public void testListSchemaEventFormat() {
+ Namespace namespace = Namespace.of("metalake", "catalog");
+ ListSchemaEvent event = new ListSchemaEvent("dave", namespace, 7);
+ SimpleAuditLogV2 log = new SimpleAuditLogV2(event);
+
+ String[] fields = log.toString().split("\t", -1);
+ Assertions.assertEquals("LIST_SCHEMA", fields[2]);
+ Assertions.assertEquals("metalake.catalog", fields[3]);
+ Assertions.assertEquals("{count=7}", fields[7]);
+ }
+
+ @Test
+ public void testListEventZeroCountInOutput() {
+ // count=0 is a valid result (empty list) and must appear in the log.
+ ListTableEvent event = new ListTableEvent("eve", Namespace.of("m", "c",
"s"), 0);
+ String[] fields = new SimpleAuditLogV2(event).toString().split("\t", -1);
+ Assertions.assertEquals("{count=0}", fields[7]);
+ }
+
+ @Test
+ public void testListEventRemoteAddressDefaultsToUnknown() {
+ // No RequestContext set — Event subclasses fall back to "unknown".
+ ListTableEvent event = new ListTableEvent("frank", Namespace.of("m", "c",
"s"), 4);
+ SimpleAuditLogV2 log = new SimpleAuditLogV2(event);
+
+ Assertions.assertEquals("unknown", log.remoteAddress());
+ String[] fields = log.toString().split("\t", -1);
+ Assertions.assertEquals("unknown", fields[6]);
+ }
+
+ @Test
+ public void testListEventCountMergedWithExistingCustomInfo() {
+ // Verify count and user-defined customInfo both appear in the audit log
field.
+ ListTableEvent base = new ListTableEvent("grace", Namespace.of("m", "c",
"s"), 9);
+ SimpleAuditLogV2 log =
+ new SimpleAuditLogV2(base) {
+ @Override
+ public java.util.Map<String, String> customInfo() {
+ return com.google.common.collect.ImmutableMap.of("env", "prod");
+ }
Review Comment:
Avoid fully qualified class names in this test override. `Map` and
`ImmutableMap` are already imported, and the repo guidelines (AGENTS.md:26-30)
prefer normal imports over inline `java.util.*` / `com.google.*` references
unless there’s a real name conflict.
##########
core/src/main/java/org/apache/gravitino/listener/api/event/ListEvent.java:
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.gravitino.listener.api.event;
+
+import org.apache.gravitino.annotation.DeveloperApi;
+
+/**
+ * Marker interface for events that represent a list operation. All
list-operation success event
+ * classes implement this interface to expose the number of items returned.
Review Comment:
The Javadoc calls this a "marker interface", but it declares a method
(`resultCount()`), so it’s not actually a marker interface. Consider rephrasing
to just "Interface for list-operation success events" (or similar) to avoid
misleading API documentation.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]