Skip to content

Commit

Permalink
Attempt to fix failing test
Browse files Browse the repository at this point in the history
Signed-off-by: Evgeniy Zuykin <[email protected]>
  • Loading branch information
SHaaD94 authored and Evgeniy Zuykin committed Jan 16, 2025
1 parent d482180 commit 0ebe3a8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 83 deletions.
24 changes: 0 additions & 24 deletions fe/fe-core/src/main/java/com/starrocks/meta/BlackListSql.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package com.starrocks.meta;

import java.util.Objects;
import java.util.regex.Pattern;

public class BlackListSql {
Expand All @@ -25,27 +24,4 @@ public BlackListSql(Pattern pattern, long id) {

public Pattern pattern;
public long id;

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
BlackListSql that = (BlackListSql) o;
if (id != that.id) {
return false;
}
if (this.pattern == null) {
return that.pattern == null;
}
return Objects.equals(pattern.pattern(), that.pattern.pattern());
}

@Override
public int hashCode() {
return Objects.hash(pattern, id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.starrocks.common.io.JsonWriter;

import java.util.List;
import java.util.Objects;

public class DeleteSqlBlackLists extends JsonWriter {
public DeleteSqlBlackLists(List<Long> ids) {
Expand All @@ -27,21 +26,4 @@ public DeleteSqlBlackLists(List<Long> ids) {

@SerializedName("ids")
public final List<Long> ids;

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DeleteSqlBlackLists that = (DeleteSqlBlackLists) o;
return Objects.equals(ids, that.ids);
}

@Override
public int hashCode() {
return Objects.hashCode(ids);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import com.google.gson.annotations.SerializedName;
import com.starrocks.common.io.JsonWriter;

import java.util.Objects;

public class SqlBlackListPersistInfo extends JsonWriter {
public SqlBlackListPersistInfo(long id, String pattern) {
this.id = id;
Expand All @@ -30,21 +28,4 @@ public SqlBlackListPersistInfo(long id, String pattern) {

@SerializedName("pattern")
public final String pattern;

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
SqlBlackListPersistInfo that = (SqlBlackListPersistInfo) o;
return id == that.id && Objects.equals(pattern, that.pattern);
}

@Override
public int hashCode() {
return Objects.hash(id, pattern);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public void testRunBackupListTable() {
minTimes = 0;
result = id.incrementAndGet();

GlobalStateMgr.getCurrentState().getNodeMgr().getClusterInfo();
globalStateMgr.getNodeMgr().getClusterInfo();
minTimes = 0;
result = systemInfoService;
}
Expand Down
62 changes: 41 additions & 21 deletions fe/fe-core/src/test/java/com/starrocks/server/SqlBlacklistTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@
import com.starrocks.sql.ast.DelSqlBlackListStmt;
import com.starrocks.sql.ast.ShowSqlBlackListStmt;
import com.starrocks.utframe.UtFrameUtils;
import mockit.Expectations;
import mockit.Mock;
import mockit.MockUp;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;

import java.util.List;
Expand Down Expand Up @@ -70,12 +69,8 @@ public void beforeEach() {
public void testAddSQLBlacklist() throws Exception {
mockupGlobalState();

new Expectations() {
{
editLog.logAddSQLBlackList(new SqlBlackListPersistInfo(0, ".+"));
times = 1;
}
};
ArgumentCaptor<SqlBlackListPersistInfo> addBlacklistEditLogArgument = ArgumentCaptor
.forClass(SqlBlackListPersistInfo.class);

AddSqlBlackListStmt addStatement = (AddSqlBlackListStmt) parseSql("ADD SQLBLACKLIST \".+\";");
Assert.assertEquals(addStatement.getSql(), ".+");
Expand All @@ -86,6 +81,11 @@ public void testAddSQLBlacklist() throws Exception {
Assert.assertEquals(1, blackLists.size());
Assert.assertEquals(0, blackLists.get(0).id);
Assert.assertEquals(".+", blackLists.get(0).pattern.pattern());

Mockito.verify(editLog).logAddSQLBlackList(addBlacklistEditLogArgument.capture());

Assert.assertEquals(0, addBlacklistEditLogArgument.getValue().id);
Assert.assertEquals(".+", addBlacklistEditLogArgument.getValue().pattern);
}

@Test
Expand All @@ -106,23 +106,32 @@ public void testShowBlacklist() {
Assert.assertFalse(resultSet.next());
}

@Test
public void testBlackListReturnsSameIdIfPatternAlreadyExists() {
mockupGlobalState();
Pattern p = Pattern.compile("qwert");
long id = sqlBlackList.put(p);

Assert.assertEquals(id, sqlBlackList.put(p));
}

@Test
public void testDeleteSqlBlacklist() throws Exception {
mockupGlobalState();
long id1 = sqlBlackList.put(Pattern.compile("qwert"));
long id2 = sqlBlackList.put(Pattern.compile("abcde"));

new Expectations() {
{
editLog.logDeleteSQLBlackList(new DeleteSqlBlackLists(List.of(id1, id2)));
times = 1;
}
};
ArgumentCaptor<DeleteSqlBlackLists> deleteBlacklistsEditLogArgument =
ArgumentCaptor.forClass(DeleteSqlBlackLists.class);

StmtExecutor deleteStatementExecutor = new StmtExecutor(connectContext, new DelSqlBlackListStmt(List.of(id1, id2)));
deleteStatementExecutor.execute();
Assert.assertTrue(sqlBlackList
.getBlackLists().stream().noneMatch(x -> x.id == id1 || x.id != id2));

Mockito.verify(editLog).logDeleteSQLBlackList(deleteBlacklistsEditLogArgument.capture());

Assert.assertEquals(List.of(id1, id2), deleteBlacklistsEditLogArgument.getValue().ids);
}

@Test
Expand All @@ -149,7 +158,17 @@ public void testSaveLoadBlackListImage() throws Exception {
SqlBlackList recoveredBlackList = new SqlBlackList();
recoveredBlackList.load(testImage.getMetaBlockReader());

Assertions.assertIterableEquals(originalBlacklist.getBlackLists(), recoveredBlackList.getBlackLists());
Assert.assertEquals(originalBlacklist.getBlackLists().size(), recoveredBlackList.getBlackLists().size());
Assert.assertEquals(originalBlacklist.getBlackLists().get(0).id, recoveredBlackList.getBlackLists().get(0).id);
Assert.assertEquals(
originalBlacklist.getBlackLists().get(0).pattern.pattern(),
recoveredBlackList.getBlackLists().get(0).pattern.pattern()
);
Assert.assertEquals(originalBlacklist.getBlackLists().get(1).id, recoveredBlackList.getBlackLists().get(1).id);
Assert.assertEquals(
originalBlacklist.getBlackLists().get(1).pattern.pattern(),
recoveredBlackList.getBlackLists().get(1).pattern.pattern()
);
}

@Test
Expand All @@ -164,19 +183,20 @@ public void testSqlBlacklistJournalOperations() throws Exception {
GlobalStateMgr.getCurrentState().getEditLog().logAddSQLBlackList(new SqlBlackListPersistInfo(1234, "p2"));
UtFrameUtils.PseudoJournalReplayer.replayJournalToEnd();

Assertions.assertIterableEquals(
List.of(new BlackListSql(Pattern.compile("p1"), 123L),
new BlackListSql(Pattern.compile("p2"), 1234L)),
GlobalStateMgr.getCurrentState().getSqlBlackList().getBlackLists()
);
List<BlackListSql> resultBlackLists = GlobalStateMgr.getCurrentState().getSqlBlackList().getBlackLists();
Assert.assertEquals(2, resultBlackLists.size());
Assert.assertEquals(123L, resultBlackLists.get(0).id);
Assert.assertEquals("p1", resultBlackLists.get(0).pattern.pattern());
Assert.assertEquals(1234L, resultBlackLists.get(1).id);
Assert.assertEquals("p2", resultBlackLists.get(1).pattern.pattern());

// delete blacklists

GlobalStateMgr.getCurrentState().getEditLog().logDeleteSQLBlackList(new DeleteSqlBlackLists(List.of(123L, 1234L)));
UtFrameUtils.PseudoJournalReplayer.replayJournalToEnd();

Assert.assertTrue(
GlobalStateMgr.getCurrentState().getSqlBlackList().getBlackLists().stream()
sqlBlackList.getBlackLists().stream()
.noneMatch(x -> x.id == 123L || x.id == 1234L)
);

Expand Down

0 comments on commit 0ebe3a8

Please sign in to comment.