DomGarguilo commented on code in PR #4082:
URL: https://github.com/apache/accumulo/pull/4082#discussion_r1428367186


##########
core/src/test/java/org/apache/accumulo/core/tabletserver/log/LogEntryTest.java:
##########
@@ -25,56 +25,60 @@
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.nio.file.Path;
-import java.util.AbstractMap;
+import java.util.AbstractMap.SimpleImmutableEntry;
 import java.util.List;
 import java.util.UUID;
 import java.util.stream.Stream;
 
 import org.apache.accumulo.core.data.Key;
-import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.core.metadata.schema.MetadataSchema;
+import 
org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
 import org.apache.hadoop.io.Text;
-import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 
 import com.google.common.net.HostAndPort;
 
 public class LogEntryTest {
 
-  private final HostAndPort validHost = HostAndPort.fromParts("default", 8080);
+  private final String validHost = "localhost+9997";
   private final UUID validUUID = UUID.randomUUID();
-  private final String validFilename = validHost + "/" + validUUID;
+  private final String validFilename = "viewfs:/a/accumulo/wal/" + validHost + 
"/" + validUUID;
 
   @Test
-  public void test() throws Exception {
-    assertEquals(new Text("log"), 
MetadataSchema.TabletsSection.LogColumnFamily.NAME);
-
-    // test from constructor
-    LogEntry one = new LogEntry(validFilename);
-    assertEquals(validFilename, one.toString());
-    assertEquals(validFilename, one.getFilePath());
-    assertEquals(new Text("-/" + validFilename), one.getColumnQualifier());
-    assertEquals(validUUID.toString(), one.getUniqueID());
-
-    // test from metadata entry
-    LogEntry two = LogEntry.fromMetaWalEntry(new 
AbstractMap.SimpleImmutableEntry<>(
-        new Key(new Text("1<"), new Text("log"), one.getColumnQualifier()), 
new Value("unused")));
-    assertNotSame(one, two);
-    assertEquals(one.toString(), two.toString());
-    assertEquals(one.getFilePath(), two.getFilePath());
-    assertEquals(one.getColumnQualifier(), two.getColumnQualifier());
-    assertEquals(one.getUniqueID(), two.getUniqueID());
-    assertEquals(one, two);
+  public void testColumnFamily() {
+    assertEquals(new Text("log"), LogColumnFamily.NAME);
+  }
+
+  @Test
+  public void testFromFilePath() throws Exception {

Review Comment:
   ```suggestion
     public void testFromFilePath() {
   ```
   These can be removed I think.



##########
core/src/test/java/org/apache/accumulo/core/tabletserver/log/LogEntryTest.java:
##########
@@ -83,50 +87,45 @@ public void testEquals() {
     assertEquals(two, two);
   }
 
-  @Nested
-  class ValidateFilePath {
-
-    @Test
-    public void testValidPaths() {
-      Path validPath = Path.of(validHost.toString(), validUUID.toString());
-      Path validPath2 = Path.of("dir1", validPath.toString());
-      Path validPath3 = Path.of("dir2", validPath2.toString());
-
-      Stream.of(validPath, validPath2, validPath3).map(Path::toString)
-          .forEach(validFilePath -> assertDoesNotThrow(() -> new 
LogEntry(validFilePath)));
-    }
-
-    @Test
-    public void testBadPathLength() {
-      List<String> badFilePaths = List.of("foo", "", validHost.toString());
-
-      for (String badFilePath : badFilePaths) {
-        IllegalArgumentException iae =
-            assertThrows(IllegalArgumentException.class, () -> new 
LogEntry(badFilePath));
-        assertTrue(iae.getMessage().contains("The path should at least contain 
tserver/UUID."));
-      }
-    }
-
-    @Test
-    public void testInvalidHostPort() {
-      final String badHostAndPort = "default:badPort";
-      final Path badFilepathHostPort = Path.of(badHostAndPort, 
validUUID.toString());
-
-      IllegalArgumentException iae = 
assertThrows(IllegalArgumentException.class,
-          () -> new LogEntry(badFilepathHostPort.toString()));
-      assertTrue(
-          iae.getMessage().contains("Expected format: host:port. Found '" + 
badHostAndPort + "'"));
-    }
-
-    @Test
-    public void testInvalidUUID() {
-      final String badUUID = "badUUID";
-      String filePathWithBadUUID = Path.of(validHost.toString(), 
badUUID).toString();
-
-      IllegalArgumentException iae =
-          assertThrows(IllegalArgumentException.class, () -> new 
LogEntry(filePathWithBadUUID));
-      assertTrue(iae.getMessage().contains("Expected valid UUID. Found '" + 
badUUID + "'"));
-    }
+  @Test
+  public void testValidPaths() {
+    Path validPath = Path.of(validHost.toString(), validUUID.toString());

Review Comment:
   Looks like `validHost` is already a `String` so the `toString()` can be 
removed. (present in a few spots in this test)



##########
core/src/main/java/org/apache/accumulo/core/tabletserver/log/LogEntry.java:
##########
@@ -27,64 +27,106 @@
 import org.apache.accumulo.core.data.Value;
 import 
org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
 import org.apache.hadoop.io.Text;
+import org.checkerframework.checker.nullness.qual.NonNull;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.net.HostAndPort;
 
-public class LogEntry {
+public final class LogEntry {
 
   private final String filePath;
+  private final HostAndPort tserver;
+  private final UUID uniqueId;
 
-  public LogEntry(String filePath) {
-    validateFilePath(filePath);
+  private LogEntry(String filePath, HostAndPort tserver, UUID uniqueId) {
     this.filePath = filePath;
-  }
-
-  public String getFilePath() {
-    return this.filePath;
+    this.tserver = tserver;
+    this.uniqueId = uniqueId;
   }
 
   /**
-   * Validates the expected format of the file path. We expect the path to 
contain a tserver
-   * (host:port) followed by a UUID as the file name. For example,
-   * localhost:1234/927ba659-d109-4bce-b0a5-bcbbcb9942a2 is a valid file path.
+   * Creates a new LogEntry object after validating the expected format of the 
file path. We expect
+   * the path to contain a tserver (host+port) followed by a UUID as the file 
name as the last two
+   * components.<br>
+   * For example, 
file:///some/dir/path/localhost+1234/927ba659-d109-4bce-b0a5-bcbbcb9942a2 is a
+   * valid file path.
    *
    * @param filePath path to validate
+   * @return an object representation of this log entry
    * @throws IllegalArgumentException if the filePath is invalid
    */
-  private static void validateFilePath(String filePath) {
+  public static LogEntry fromFilePath(String filePath) {

Review Comment:
   Seems fine without it but do you think it would be helpful to have another 
static entry point that accepts a `Path` object? Or even replace the type of 
the `filePath` member variable with `Path`?
   
   It seems like a lot of the places in the code convert from a `Path` to a 
`String` when using this method.



-- 
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: notifications-unsubscr...@accumulo.apache.org

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

Reply via email to