Skip to content

Commit

Permalink
throw IllegalStateException in LogManagerImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
alievmirza committed Sep 27, 2024
1 parent 1b2cea2 commit 09f1523
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,11 @@ public long getLastLogIndex(final boolean isFlush) {
Thread.currentThread().interrupt();
throw new IllegalStateException(e);
}
if (c.lastLogId == null) {
assert stopped : "Last log id can be null only when node is stopping.";

throw new IllegalStateException("Node is shutting down");
}
return c.lastLogId.getIndex();
}

Expand Down Expand Up @@ -895,17 +900,9 @@ public LogId getLastLogId(final boolean isFlush) {
throw new IllegalStateException(e);
}
if (c.lastLogId == null) {
assert stopped;

try {
shutDownLatch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();

throw new IllegalStateException(e);
}
assert stopped : "Last log id can be null only when node is stopping.";

return new LogId(this.lastLogIndex, unsafeGetTerm(this.lastLogIndex));
throw new IllegalStateException("Node is shutting down");
}
return c.lastLogId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

@RunWith(value = MockitoJUnitRunner.class)
Expand Down Expand Up @@ -416,4 +417,23 @@ public void testCheckAndSetConfiguration() throws Exception {
assertEquals("localhost:8081,localhost:8082", lastEntry.getOldConf().toString());
}

@Test
public void testLastLogIdWhenShutdown() throws Exception {
mockAddEntries();
assertEquals(1, this.logManager.getFirstLogIndex());
assertEquals(10, this.logManager.getLastLogIndex());
this.logManager.shutdown();
Exception e = assertThrows(IllegalStateException.class, () -> this.logManager.getLastLogId(true));
assertEquals("Node is shutting down", e.getMessage());
}

@Test
public void testLastLogIndexWhenShutdown() throws Exception {
mockAddEntries();
assertEquals(1, this.logManager.getFirstLogIndex());
assertEquals(10, this.logManager.getLastLogIndex());
this.logManager.shutdown();
Exception e = assertThrows(IllegalStateException.class, () -> this.logManager.getLastLogIndex(true));
assertEquals("Node is shutting down", e.getMessage());
}
}

0 comments on commit 09f1523

Please sign in to comment.