dlmarion commented on code in PR #3409:
URL: https://github.com/apache/accumulo/pull/3409#discussion_r1202857679


##########
server/base/src/test/java/org/apache/accumulo/server/manager/state/TabletMetadataImposterTest.java:
##########
@@ -18,171 +18,171 @@
  */
 package org.apache.accumulo.server.manager.state;
 
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.createNiceMock;
 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.assertSame;
-import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-import java.util.Collection;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.accumulo.core.client.admin.TabletHostingGoal;
 import org.apache.accumulo.core.dataImpl.KeyExtent;
 import org.apache.accumulo.core.metadata.TServerInstance;
-import org.apache.accumulo.core.metadata.TabletLocationState;
 import org.apache.accumulo.core.metadata.TabletState;
+import org.apache.accumulo.core.metadata.schema.TabletMetadata;
 import org.apache.accumulo.core.metadata.schema.TabletMetadata.Location;
-import org.apache.hadoop.io.Text;
-import org.junit.jupiter.api.BeforeAll;
+import org.apache.accumulo.core.tabletserver.log.LogEntry;
+import org.easymock.EasyMock;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-public class CachedTabletStateTest {
-  private static final Collection<String> innerWalogs = new 
java.util.HashSet<>();
-  private static final Collection<Collection<String>> walogs = new 
java.util.HashSet<>();
-
-  @BeforeAll
-  public static void setUpClass() {
-    walogs.add(innerWalogs);
-    innerWalogs.add("somelog");
-  }
+public class TabletMetadataImposterTest {
 
   private KeyExtent keyExtent;
   private Location future;
   private Location current;
   private Location last;
-  private TabletLocationState tls;
+  private TabletMetadata tls;
+  private List<LogEntry> walogs = new ArrayList<>();
 
   @BeforeEach
   public void setUp() {
-    keyExtent = createMock(KeyExtent.class);
-    future = Location.future(createMock(TServerInstance.class));
-    current = Location.current(createMock(TServerInstance.class));
-    last = Location.last(createMock(TServerInstance.class));
+    keyExtent = createNiceMock(KeyExtent.class);
+    TServerInstance futureInstance = createNiceMock(TServerInstance.class);
+    future = Location.future(futureInstance);
+    TServerInstance currentInstance = createNiceMock(TServerInstance.class);
+    current = Location.current(currentInstance);
+    TServerInstance lastInstance = createNiceMock(TServerInstance.class);
+    last = Location.last(lastInstance);
+    walogs.clear();
+    walogs.add(new LogEntry(keyExtent, 1234L, "some file name"));
+    EasyMock.replay(keyExtent, futureInstance, currentInstance, lastInstance);
   }
 
   @Test
   public void testConstruction_NoFuture() throws Exception {
-    tls = new TabletLocationState(keyExtent, null, current, last, null, 
walogs, true,
+    tls = new TabletMetadataImposter(keyExtent, null, current, last, null, 
walogs, true,
         TabletHostingGoal.ONDEMAND, false);
-    assertSame(keyExtent, tls.extent);
-    assertNull(tls.future);
-    assertSame(current, tls.current);
-    assertSame(last, tls.last);
-    assertSame(walogs, tls.walogs);
-    assertTrue(tls.chopped);
+    assertSame(keyExtent, tls.getExtent());
+    assertTrue(tls.hasCurrent());
+    assertSame(current, tls.getLocation());
+    assertSame(last, tls.getLast());
+    assertSame(walogs, tls.getLogs());
+    assertTrue(tls.hasChopped());
   }
 
   @Test
   public void testConstruction_NoCurrent() throws Exception {
-    tls = new TabletLocationState(keyExtent, future, null, last, null, walogs, 
true,
+    tls = new TabletMetadataImposter(keyExtent, future, null, last, null, 
walogs, true,
         TabletHostingGoal.ONDEMAND, false);
-    assertSame(keyExtent, tls.extent);
-    assertSame(future, tls.future);
-    assertNull(tls.current);
-    assertSame(last, tls.last);
-    assertSame(walogs, tls.walogs);
-    assertTrue(tls.chopped);
+    assertSame(keyExtent, tls.getExtent());
+    assertSame(future, tls.getLocation());
+    assertFalse(tls.hasCurrent());
+    assertSame(last, tls.getLast());
+    assertSame(walogs, tls.getLogs());
+    assertTrue(tls.hasChopped());
   }
 
   @Test
   public void testConstruction_FutureAndCurrent() {
-    expect(keyExtent.toMetaRow()).andReturn(new Text("entry"));
-    replay(keyExtent);
-    var e = assertThrows(TabletLocationState.BadLocationStateException.class,
-        () -> new TabletLocationState(keyExtent, future, current, last, null, 
walogs, true,
-            TabletHostingGoal.ONDEMAND, false));
-    assertEquals(new Text("entry"), e.getEncodedEndRow());
+    tls = new TabletMetadataImposter(keyExtent, future, current, last, null, 
walogs, true,
+        TabletHostingGoal.ONDEMAND, false);
+    assertTrue(tls.isFutureAndCurrentLocationSet());
   }
 
   @Test
   public void testConstruction_NoFuture_NoWalogs() throws Exception {
-    tls = new TabletLocationState(keyExtent, null, current, last, null, null, 
true,
+    tls = new TabletMetadataImposter(keyExtent, null, current, last, null, 
null, true,
         TabletHostingGoal.ONDEMAND, false);
-    assertNotNull(tls.walogs);
-    assertEquals(0, tls.walogs.size());
+    assertNotNull(tls.getLogs());
+    assertEquals(0, tls.getLogs().size());
   }
 
   @Test
   public void testGetServer_Current() throws Exception {
-    tls = new TabletLocationState(keyExtent, null, current, last, null, 
walogs, true,
+    tls = new TabletMetadataImposter(keyExtent, null, current, last, null, 
walogs, true,
         TabletHostingGoal.ONDEMAND, false);
+    assertTrue(tls.hasCurrent());
     assertSame(current, tls.getLocation());
   }
 
   @Test
   public void testGetServer_Future() throws Exception {
-    tls = new TabletLocationState(keyExtent, future, null, last, null, walogs, 
true,
+    tls = new TabletMetadataImposter(keyExtent, future, null, last, null, 
walogs, true,
         TabletHostingGoal.ONDEMAND, false);
+    assertFalse(tls.hasCurrent());
     assertSame(future, tls.getLocation());
   }
 
   @Test
   public void testGetServer_Last() throws Exception {
-    tls = new TabletLocationState(keyExtent, null, null, last, null, walogs, 
true,
+    tls = new TabletMetadataImposter(keyExtent, null, null, last, null, 
walogs, true,
         TabletHostingGoal.ONDEMAND, false);
-    assertSame(last, tls.getLocation());
+    assertFalse(tls.hasCurrent());
+    assertNull(tls.getLocation());
+    assertSame(last, tls.getLast());
   }
 
   @Test
   public void testGetServer_None() throws Exception {
-    tls = new TabletLocationState(keyExtent, null, null, null, null, walogs, 
true,
+    tls = new TabletMetadataImposter(keyExtent, null, null, null, null, 
walogs, true,
         TabletHostingGoal.ONDEMAND, false);
+    assertFalse(tls.hasCurrent());
     assertNull(tls.getLocation());
   }
 
   @Test
   public void testGetState_Unassigned1() throws Exception {
-    tls = new TabletLocationState(keyExtent, null, null, null, null, walogs, 
true,
+    tls = new TabletMetadataImposter(keyExtent, null, null, null, null, 
walogs, true,
         TabletHostingGoal.ONDEMAND, false);
-    assertEquals(TabletState.UNASSIGNED, tls.getState(null));
+    assertEquals(TabletState.UNASSIGNED, tls.getTabletState(null));

Review Comment:
   Yeah, TabletMetadataImposter and it's test, are derived from the old 
TabletLocationState objects.



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

Reply via email to