This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push:
new 753a7dd Replace PowerMock/EasyMock by Jmockit (3/4)
753a7dd is described below
commit 753a7dd73a3f00502d523844fad5ceef8291620f
Author: xy720 <[email protected]>
AuthorDate: Thu Jan 16 13:24:43 2020 +0800
Replace PowerMock/EasyMock by Jmockit (3/4)
---
.../apache/doris/analysis/AddColumnClauseTest.java | 146 +++++++---
.../apache/doris/analysis/CancelAlterStmtTest.java | 8 -
.../apache/doris/analysis/DropTableStmtTest.java | 18 +-
.../org/apache/doris/analysis/LabelNameTest.java | 40 ++-
.../doris/analysis/ModifyColumnClauseTest.java | 25 +-
.../doris/catalog/MaterializedIndexTest.java | 24 +-
.../doris/common/proc/BackendsProcDirTest.java | 132 +++++----
.../org/apache/doris/mysql/MysqlChannelTest.java | 297 ++++++++++++---------
.../doris/mysql/MysqlHandshakePacketTest.java | 25 +-
.../org/apache/doris/mysql/MysqlProtoTest.java | 157 ++++++-----
.../org/apache/doris/mysql/MysqlServerTest.java | 31 ++-
.../org/apache/doris/qe/SimpleSchedulerTest.java | 53 ++--
.../org/apache/doris/task/LoadEtlTaskTest.java | 93 ++++---
.../org/apache/doris/task/LoadPendingTaskTest.java | 106 +++++---
14 files changed, 695 insertions(+), 460 deletions(-)
diff --git
a/fe/src/test/java/org/apache/doris/analysis/AddColumnClauseTest.java
b/fe/src/test/java/org/apache/doris/analysis/AddColumnClauseTest.java
index 410903e..f966340 100644
--- a/fe/src/test/java/org/apache/doris/analysis/AddColumnClauseTest.java
+++ b/fe/src/test/java/org/apache/doris/analysis/AddColumnClauseTest.java
@@ -17,10 +17,11 @@
package org.apache.doris.analysis;
+import mockit.Expectations;
+import mockit.Mocked;
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.PrimitiveType;
import org.apache.doris.catalog.ScalarType;
-import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -31,6 +32,9 @@ import org.apache.doris.common.AnalysisException;
public class AddColumnClauseTest {
private static Analyzer analyzer;
+ @Mocked
+ ColumnDef definition;
+
@BeforeClass
public static void setUp() {
analyzer = AccessTestUtil.fetchAdminAnalyzer(false);
@@ -39,15 +43,32 @@ public class AddColumnClauseTest {
@Test
public void testNormal() throws AnalysisException {
Column column = new Column("testCol",
ScalarType.createType(PrimitiveType.INT));
- ColumnDef definition = EasyMock.createMock(ColumnDef.class);
- definition.analyze(true);
- EasyMock.expectLastCall().anyTimes();
- EasyMock.expect(definition.toSql()).andReturn("`testCol`
INT").anyTimes();
- EasyMock.expect(definition.getDefaultValue()).andReturn("").anyTimes();
-
EasyMock.expect(definition.getAggregateType()).andReturn(null).anyTimes();
- EasyMock.expect(definition.isAllowNull()).andReturn(false).anyTimes();
- EasyMock.expect(definition.toColumn()).andReturn(column).anyTimes();
- EasyMock.replay(definition);
+ new Expectations() {
+ {
+ definition.analyze(true);
+ minTimes = 0;
+
+ definition.toSql();
+ minTimes = 0;
+ result = "`testCol` INT";
+
+ definition.getDefaultValue();
+ minTimes = 0;
+ result = "";
+
+ definition.getAggregateType();
+ minTimes = 0;
+ result = null;
+
+ definition.isAllowNull();
+ minTimes = 0;
+ result = false;
+
+ definition.toColumn();
+ minTimes = 0;
+ result = column;
+ }
+ };
AddColumnClause clause = new AddColumnClause(definition, null, null,
null);
clause.analyze(analyzer);
@@ -78,15 +99,32 @@ public class AddColumnClauseTest {
@Test(expected = AnalysisException.class)
public void testNoDefault() throws AnalysisException {
- ColumnDef definition = EasyMock.createMock(ColumnDef.class);
- definition.analyze(true);
- EasyMock.expectLastCall().anyTimes();
- EasyMock.expect(definition.toSql()).andReturn("`testCol`
INT").anyTimes();
-
EasyMock.expect(definition.getDefaultValue()).andReturn(null).anyTimes();
-
EasyMock.expect(definition.getAggregateType()).andReturn(null).anyTimes();
- EasyMock.expect(definition.getName()).andReturn("testCol").anyTimes();
- EasyMock.expect(definition.isAllowNull()).andReturn(false).anyTimes();
- EasyMock.replay(definition);
+ new Expectations() {
+ {
+ definition.analyze(true);
+ minTimes = 0;
+
+ definition.toSql();
+ minTimes = 0;
+ result = "`testCol` INT";
+
+ definition.getDefaultValue();
+ minTimes = 0;
+ result = null;
+
+ definition.getAggregateType();
+ minTimes = 0;
+ result = null;
+
+ definition.getName();
+ minTimes = 0;
+ result = "testCol";
+
+ definition.isAllowNull();
+ minTimes = 0;
+ result = false;
+ }
+ };
AddColumnClause clause = new AddColumnClause(definition, null, null,
null);
clause.analyze(analyzer);
Assert.fail("No exception throws.");
@@ -94,15 +132,32 @@ public class AddColumnClauseTest {
@Test(expected = AnalysisException.class)
public void testAggPos() throws AnalysisException {
- ColumnDef definition = EasyMock.createMock(ColumnDef.class);
- definition.analyze(true);
- EasyMock.expectLastCall().anyTimes();
- EasyMock.expect(definition.toSql()).andReturn("`testCol`
INT").anyTimes();
-
EasyMock.expect(definition.getDefaultValue()).andReturn(null).anyTimes();
-
EasyMock.expect(definition.getAggregateType()).andReturn(AggregateType.SUM).anyTimes();
- EasyMock.expect(definition.getName()).andReturn("testCol").anyTimes();
- EasyMock.expect(definition.isAllowNull()).andReturn(false).anyTimes();
- EasyMock.replay(definition);
+ new Expectations() {
+ {
+ definition.analyze(true);
+ minTimes = 0;
+
+ definition.toSql();
+ minTimes = 0;
+ result = "`testCol` INT";
+
+ definition.getDefaultValue();
+ minTimes = 0;
+ result = null;
+
+ definition.getAggregateType();
+ minTimes = 0;
+ result = AggregateType.SUM;
+
+ definition.getName();
+ minTimes = 0;
+ result = "testCol";
+
+ definition.isAllowNull();
+ minTimes = 0;
+ result = false;
+ }
+ };
AddColumnClause clause = new AddColumnClause(definition,
ColumnPosition.FIRST, null, null);
clause.analyze(analyzer);
Assert.fail("No exception throws.");
@@ -110,15 +165,32 @@ public class AddColumnClauseTest {
@Test(expected = AnalysisException.class)
public void testAddValueToFirst() throws AnalysisException {
- ColumnDef definition = EasyMock.createMock(ColumnDef.class);
- definition.analyze(true);
- EasyMock.expectLastCall().anyTimes();
- EasyMock.expect(definition.toSql()).andReturn("`testCol`
INT").anyTimes();
-
EasyMock.expect(definition.getDefaultValue()).andReturn("2").anyTimes();
-
EasyMock.expect(definition.getAggregateType()).andReturn(AggregateType.SUM).anyTimes();
- EasyMock.expect(definition.getName()).andReturn("testCol").anyTimes();
- EasyMock.expect(definition.isAllowNull()).andReturn(false).anyTimes();
- EasyMock.replay(definition);
+ new Expectations() {
+ {
+ definition.analyze(true);
+ minTimes = 0;
+
+ definition.toSql();
+ minTimes = 0;
+ result = "`testCol` INT";
+
+ definition.getDefaultValue();
+ minTimes = 0;
+ result = "2";
+
+ definition.getAggregateType();
+ minTimes = 0;
+ result = AggregateType.SUM;
+
+ definition.getName();
+ minTimes = 0;
+ result = "testCol";
+
+ definition.isAllowNull();
+ minTimes = 0;
+ result = false;
+ }
+ };
AddColumnClause clause = new AddColumnClause(definition,
ColumnPosition.FIRST, null, null);
clause.analyze(analyzer);
Assert.fail("No exception throws.");
diff --git
a/fe/src/test/java/org/apache/doris/analysis/CancelAlterStmtTest.java
b/fe/src/test/java/org/apache/doris/analysis/CancelAlterStmtTest.java
index 7ea31e9..9fdc95d 100644
--- a/fe/src/test/java/org/apache/doris/analysis/CancelAlterStmtTest.java
+++ b/fe/src/test/java/org/apache/doris/analysis/CancelAlterStmtTest.java
@@ -26,19 +26,11 @@ import org.apache.doris.catalog.Catalog;
import org.apache.doris.catalog.FakeCatalog;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.UserException;
-import org.apache.doris.mysql.privilege.PaloAuth;
-import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;
-import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.api.easymock.PowerMock;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
public class CancelAlterStmtTest {
diff --git a/fe/src/test/java/org/apache/doris/analysis/DropTableStmtTest.java
b/fe/src/test/java/org/apache/doris/analysis/DropTableStmtTest.java
index 414b9a0..8c28d0d 100644
--- a/fe/src/test/java/org/apache/doris/analysis/DropTableStmtTest.java
+++ b/fe/src/test/java/org/apache/doris/analysis/DropTableStmtTest.java
@@ -17,13 +17,13 @@
package org.apache.doris.analysis;
+import mockit.Expectations;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.UserException;
import org.apache.doris.mysql.privilege.MockedAuth;
import org.apache.doris.mysql.privilege.PaloAuth;
import org.apache.doris.qe.ConnectContext;
-import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -34,6 +34,7 @@ public class DropTableStmtTest {
private TableName tbl;
private TableName noDbTbl;
private Analyzer analyzer;
+ @Mocked
private Analyzer noDbAnalyzer;
@Mocked
@@ -47,10 +48,17 @@ public class DropTableStmtTest {
noDbTbl = new TableName("", "table1");
analyzer = AccessTestUtil.fetchAdminAnalyzer(true);
- noDbAnalyzer = EasyMock.createMock(Analyzer.class);
- EasyMock.expect(noDbAnalyzer.getDefaultDb()).andReturn("").anyTimes();
-
EasyMock.expect(noDbAnalyzer.getClusterName()).andReturn("testCluster").anyTimes();
- EasyMock.replay(noDbAnalyzer);
+ new Expectations() {
+ {
+ noDbAnalyzer.getDefaultDb();
+ minTimes = 0;
+ result = "";
+
+ noDbAnalyzer.getClusterName();
+ minTimes = 0;
+ result = "testCluster";
+ }
+ };
MockedAuth.mockedAuth(auth);
MockedAuth.mockedConnectContext(ctx, "root", "192.168.1.1");
diff --git a/fe/src/test/java/org/apache/doris/analysis/LabelNameTest.java
b/fe/src/test/java/org/apache/doris/analysis/LabelNameTest.java
index d52708b..e2e367a 100644
--- a/fe/src/test/java/org/apache/doris/analysis/LabelNameTest.java
+++ b/fe/src/test/java/org/apache/doris/analysis/LabelNameTest.java
@@ -17,26 +17,38 @@
package org.apache.doris.analysis;
+import mockit.Expectations;
+import mockit.Mocked;
import org.apache.doris.common.AnalysisException;
import org.junit.Assert;
-import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
public class LabelNameTest {
+ @Mocked
private Analyzer analyzer;
@Before
public void setUp() {
- analyzer = EasyMock.createMock(Analyzer.class);
-
EasyMock.expect(analyzer.getClusterName()).andReturn("testCluster").anyTimes();
+ new Expectations() {
+ {
+ analyzer.getClusterName();
+ minTimes = 0;
+ result = "testCluster";
+ }
+ };
}
@Test
public void testNormal() throws AnalysisException {
-
EasyMock.expect(analyzer.getDefaultDb()).andReturn("testDb").anyTimes();
- EasyMock.replay(analyzer);
+ new Expectations() {
+ {
+ analyzer.getDefaultDb();
+ minTimes = 0;
+ result = "testDb";
+ }
+ };
LabelName label = new LabelName("testDb", "testLabel");
label.analyze(analyzer);
@@ -51,8 +63,13 @@ public class LabelNameTest {
@Test(expected = AnalysisException.class)
public void testNoDb() throws AnalysisException {
- EasyMock.expect(analyzer.getDefaultDb()).andReturn(null).anyTimes();
- EasyMock.replay(analyzer);
+ new Expectations() {
+ {
+ analyzer.getDefaultDb();
+ minTimes = 0;
+ result = null;
+ }
+ };
LabelName label = new LabelName("", "testLabel");
label.analyze(analyzer);
@@ -61,8 +78,13 @@ public class LabelNameTest {
@Test(expected = AnalysisException.class)
public void testNoLabel() throws AnalysisException {
-
EasyMock.expect(analyzer.getDefaultDb()).andReturn("testDb").anyTimes();
- EasyMock.replay(analyzer);
+ new Expectations() {
+ {
+ analyzer.getDefaultDb();
+ minTimes = 0;
+ result = "testDb";
+ }
+ };
LabelName label = new LabelName("", "");
label.analyze(analyzer);
diff --git
a/fe/src/test/java/org/apache/doris/analysis/ModifyColumnClauseTest.java
b/fe/src/test/java/org/apache/doris/analysis/ModifyColumnClauseTest.java
index b3bf907..074678b 100644
--- a/fe/src/test/java/org/apache/doris/analysis/ModifyColumnClauseTest.java
+++ b/fe/src/test/java/org/apache/doris/analysis/ModifyColumnClauseTest.java
@@ -17,8 +17,9 @@
package org.apache.doris.analysis;
+import mockit.Expectations;
+import mockit.Mocked;
import org.apache.doris.catalog.PrimitiveType;
-import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -35,14 +36,22 @@ public class ModifyColumnClauseTest {
}
@Test
- public void testNormal() throws AnalysisException {
+ public void testNormal(@Mocked ColumnDef definition) throws
AnalysisException {
Column column = new Column("tsetCol", PrimitiveType.INT);
- ColumnDef definition = EasyMock.createMock(ColumnDef.class);
- definition.analyze(true);
- EasyMock.expectLastCall().anyTimes();
- EasyMock.expect(definition.toSql()).andReturn("`testCol`
INT").anyTimes();
- EasyMock.expect(definition.toColumn()).andReturn(column).anyTimes();
- EasyMock.replay(definition);
+ new Expectations() {
+ {
+ definition.analyze(true);
+ minTimes = 0;
+
+ definition.toSql();
+ minTimes = 0;
+ result = "`testCol` INT";
+
+ definition.toColumn();
+ minTimes = 0;
+ result = column;
+ }
+ };
ModifyColumnClause clause = new ModifyColumnClause(definition, null,
null, null);
clause.analyze(analyzer);
diff --git
a/fe/src/test/java/org/apache/doris/catalog/MaterializedIndexTest.java
b/fe/src/test/java/org/apache/doris/catalog/MaterializedIndexTest.java
index 205c69d..a04432d 100644
--- a/fe/src/test/java/org/apache/doris/catalog/MaterializedIndexTest.java
+++ b/fe/src/test/java/org/apache/doris/catalog/MaterializedIndexTest.java
@@ -17,6 +17,7 @@
package org.apache.doris.catalog;
+import mockit.Mocked;
import org.apache.doris.catalog.MaterializedIndex.IndexState;
import org.apache.doris.common.FeConstants;
@@ -28,27 +29,21 @@ import java.io.FileOutputStream;
import java.util.LinkedList;
import java.util.List;
-import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.api.easymock.PowerMock;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockIgnore({ "org.apache.log4j.*", "javax.management.*" })
-@PrepareForTest(Catalog.class)
+
public class MaterializedIndexTest {
private MaterializedIndex index;
private long indexId;
private List<Column> columns;
+ @Mocked
private Catalog catalog;
+ private FakeCatalog fakeCatalog;
+
@Before
public void setUp() {
indexId = 10000;
@@ -59,12 +54,9 @@ public class MaterializedIndexTest {
columns.add(new Column("v1", ScalarType.createType(PrimitiveType.INT),
false, AggregateType.REPLACE, "", ""));
index = new MaterializedIndex(indexId, IndexState.NORMAL);
- catalog = EasyMock.createMock(Catalog.class);
-
- PowerMock.mockStatic(Catalog.class);
- EasyMock.expect(Catalog.getInstance()).andReturn(catalog).anyTimes();
-
EasyMock.expect(Catalog.getCurrentCatalogJournalVersion()).andReturn(FeConstants.meta_version).anyTimes();
- PowerMock.replay(Catalog.class);
+ fakeCatalog = new FakeCatalog();
+ FakeCatalog.setCatalog(catalog);
+ FakeCatalog.setMetaVersion(FeConstants.meta_version);
}
@Test
diff --git
a/fe/src/test/java/org/apache/doris/common/proc/BackendsProcDirTest.java
b/fe/src/test/java/org/apache/doris/common/proc/BackendsProcDirTest.java
index 642ca55..ab97881 100644
--- a/fe/src/test/java/org/apache/doris/common/proc/BackendsProcDirTest.java
+++ b/fe/src/test/java/org/apache/doris/common/proc/BackendsProcDirTest.java
@@ -17,6 +17,8 @@
package org.apache.doris.common.proc;
+import mockit.Expectations;
+import mockit.Mocked;
import org.apache.doris.catalog.Catalog;
import org.apache.doris.catalog.TabletInvertedIndex;
import org.apache.doris.common.AnalysisException;
@@ -24,75 +26,91 @@ import org.apache.doris.persist.EditLog;
import org.apache.doris.system.Backend;
import org.apache.doris.system.SystemInfoService;
-import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.api.easymock.PowerMock;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-@RunWith(PowerMockRunner.class)
-@PowerMockIgnore({ "org.apache.log4j.*", "javax.management.*" })
-@PrepareForTest(Catalog.class)
+
public class BackendsProcDirTest {
- private static Backend b1;
- private static Backend b2;
-
- private static SystemInfoService systemInfoService;
- private static TabletInvertedIndex tabletInvertedIndex;
-
- private static Catalog catalog;
- private static EditLog editLog;
-
- // construct test case
- @BeforeClass
- public static void setUpClass() {
- editLog = EasyMock.createMock(EditLog.class);
- editLog.logAddBackend(EasyMock.anyObject(Backend.class));
- EasyMock.expectLastCall().anyTimes();
- editLog.logDropBackend(EasyMock.anyObject(Backend.class));
- EasyMock.expectLastCall().anyTimes();
- editLog.logBackendStateChange(EasyMock.anyObject(Backend.class));
- EasyMock.expectLastCall().anyTimes();
- EasyMock.replay(editLog);
-
- catalog = EasyMock.createMock(Catalog.class);
- EasyMock.expect(catalog.getNextId()).andReturn(10000L).anyTimes();
- EasyMock.expect(catalog.getEditLog()).andReturn(editLog).anyTimes();
- catalog.clear();
- EasyMock.expectLastCall().anyTimes();
- EasyMock.replay(catalog);
+ private Backend b1;
+ private Backend b2;
+
+ @Mocked
+ private SystemInfoService systemInfoService;
+ @Mocked
+ private TabletInvertedIndex tabletInvertedIndex;
+ @Mocked
+ private Catalog catalog;
+ @Mocked
+ private EditLog editLog;
+ @Before
+ public void setUp() {
b1 = new Backend(1000, "host1", 10000);
b1.updateOnce(10001, 10003, 10005);
b2 = new Backend(1001, "host2", 20000);
b2.updateOnce(20001, 20003, 20005);
- systemInfoService = EasyMock.createNiceMock(SystemInfoService.class);
-
EasyMock.expect(systemInfoService.getBackend(1000)).andReturn(b1).anyTimes();
-
EasyMock.expect(systemInfoService.getBackend(1001)).andReturn(b2).anyTimes();
-
EasyMock.expect(systemInfoService.getBackend(1002)).andReturn(null).anyTimes();
- EasyMock.replay(systemInfoService);
-
- tabletInvertedIndex =
EasyMock.createNiceMock(TabletInvertedIndex.class);
-
EasyMock.expect(tabletInvertedIndex.getTabletNumByBackendId(EasyMock.anyLong())).andReturn(2).anyTimes();
- EasyMock.replay(tabletInvertedIndex);
-
- PowerMock.mockStatic(Catalog.class);
- EasyMock.expect(Catalog.getInstance()).andReturn(catalog).anyTimes();
-
EasyMock.expect(Catalog.getCurrentSystemInfo()).andReturn(systemInfoService).anyTimes();
-
EasyMock.expect(Catalog.getCurrentInvertedIndex()).andReturn(tabletInvertedIndex).anyTimes();
- PowerMock.replay(Catalog.class);
- }
+ new Expectations() {
+ {
+ editLog.logAddBackend((Backend) any);
+ minTimes = 0;
+
+ editLog.logDropBackend((Backend) any);
+ minTimes = 0;
+
+ editLog.logBackendStateChange((Backend) any);
+ minTimes = 0;
+
+ catalog.getNextId();
+ minTimes = 0;
+ result = 10000L;
+
+ catalog.getEditLog();
+ minTimes = 0;
+ result = editLog;
+
+ catalog.clear();
+ minTimes = 0;
+
+ systemInfoService.getBackend(1000);
+ minTimes = 0;
+ result = b1;
+
+ systemInfoService.getBackend(1001);
+ minTimes = 0;
+ result = b2;
+
+ systemInfoService.getBackend(1002);
+ minTimes = 0;
+ result = null;
+
+ tabletInvertedIndex.getTabletNumByBackendId(anyLong);
+ minTimes = 0;
+ result = 2;
+ }
+ };
+
+ new Expectations(catalog) {
+ {
+ Catalog.getInstance();
+ minTimes = 0;
+ result = catalog;
+
+ Catalog.getCurrentCatalog();
+ minTimes = 0;
+ result = catalog;
+
+ Catalog.getCurrentInvertedIndex();
+ minTimes = 0;
+ result = tabletInvertedIndex;
+
+ Catalog.getCurrentSystemInfo();
+ minTimes = 0;
+ result = systemInfoService;
+ }
+ };
- @Before
- public void setUp() {
- // systemInfoService =
EasyMock.createNiceMock(SystemInfoService.class);
}
@After
diff --git a/fe/src/test/java/org/apache/doris/mysql/MysqlChannelTest.java
b/fe/src/test/java/org/apache/doris/mysql/MysqlChannelTest.java
index 3474a72..417480e 100644
--- a/fe/src/test/java/org/apache/doris/mysql/MysqlChannelTest.java
+++ b/fe/src/test/java/org/apache/doris/mysql/MysqlChannelTest.java
@@ -17,7 +17,9 @@
package org.apache.doris.mysql;
-import org.easymock.EasyMock;
+import mockit.Delegate;
+import mockit.Expectations;
+import mockit.Mocked;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -30,44 +32,54 @@ import java.nio.channels.SocketChannel;
public class MysqlChannelTest {
int packetId = 0;
int readIdx = 0;
+ @Mocked
private SocketChannel channel;
@Before
public void setUp() throws IOException {
packetId = 0;
readIdx = 0;
- channel = EasyMock.createMock(SocketChannel.class);
- EasyMock.expect(channel.getRemoteAddress()).andReturn(new
InetSocketAddress(1024)).anyTimes();
+ new Expectations() {
+ {
+ channel.getRemoteAddress();
+ minTimes = 0;
+ result = new InetSocketAddress(1024);
+ }
+ };
}
@Test
public void testReceive() throws IOException {
// mock
-
EasyMock.expect(channel.read(EasyMock.anyObject(ByteBuffer.class))).andDelegateTo(new
WrapperSocketChannel() {
- @Override
- public int read(ByteBuffer buffer) {
- MysqlSerializer serializer = MysqlSerializer.newInstance();
- if (readIdx == 0) {
- readIdx++;
- serializer.writeInt3(10);
- serializer.writeInt1(packetId++);
-
- buffer.put(serializer.toArray());
- return 4;
- } else if (readIdx == 1) {
- readIdx++;
- byte[] buf = new byte[buffer.remaining()];
- for (int i = 0; i < buffer.remaining(); ++i) {
- buf[i] = (byte) ('a' + i);
-
+ new Expectations() {
+ {
+ channel.read((ByteBuffer) any);
+ minTimes = 0;
+ result = new Delegate() {
+ int fakeRead(ByteBuffer buffer) {
+ MysqlSerializer serializer =
MysqlSerializer.newInstance();
+ if (readIdx == 0) {
+ readIdx++;
+ serializer.writeInt3(10);
+ serializer.writeInt1(packetId++);
+
+ buffer.put(serializer.toArray());
+ return 4;
+ } else if (readIdx == 1) {
+ readIdx++;
+ byte[] buf = new byte[buffer.remaining()];
+ for (int i = 0; i < buffer.remaining(); ++i) {
+ buf[i] = (byte) ('a' + i);
+
+ }
+ buffer.put(buf);
+ return 10;
+ }
+ return -1;
}
- buffer.put(buf);
- return 10;
- }
- return -1;
+ };
}
- }).anyTimes();
- EasyMock.replay(channel);
+ };
MysqlChannel channel1 = new MysqlChannel(channel);
@@ -81,53 +93,56 @@ public class MysqlChannelTest {
@Test
public void testLongPacket() throws IOException {
// mock
-
EasyMock.expect(channel.read(EasyMock.anyObject(ByteBuffer.class))).andDelegateTo(new
WrapperSocketChannel() {
- @Override
- public int read(ByteBuffer buffer) {
- int maxLen = 0xffffff - 1;
- MysqlSerializer serializer = MysqlSerializer.newInstance();
- if (readIdx == 0) {
- // packet
- readIdx++;
- serializer.writeInt3(maxLen);
- serializer.writeInt1(packetId++);
-
- buffer.put(serializer.toArray());
- return 4;
- } else if (readIdx == 1) {
- readIdx++;
- int readLen = buffer.remaining();
- byte[] buf = new byte[readLen];
- for (int i = 0; i < readLen; ++i) {
- buf[i] = (byte) ('a' + (i % 26));
-
- }
- buffer.put(buf);
- return readLen;
- } else if (readIdx == 2) {
- // packet
- readIdx++;
- serializer.writeInt3(10);
- serializer.writeInt1(packetId++);
-
- buffer.put(serializer.toArray());
- return 4;
- } else if (readIdx == 3) {
- readIdx++;
- int readLen = buffer.remaining();
- byte[] buf = new byte[readLen];
- for (int i = 0; i < readLen; ++i) {
- buf[i] = (byte) ('a' + (maxLen + i) % 26);
-
+ new Expectations() {
+ {
+ channel.read((ByteBuffer) any);
+ minTimes = 0;
+ result = new Delegate() {
+ int fakeRead(ByteBuffer buffer) {
+ int maxLen = 0xffffff - 1;
+ MysqlSerializer serializer =
MysqlSerializer.newInstance();
+ if (readIdx == 0) {
+ // packet
+ readIdx++;
+ serializer.writeInt3(maxLen);
+ serializer.writeInt1(packetId++);
+
+ buffer.put(serializer.toArray());
+ return 4;
+ } else if (readIdx == 1) {
+ readIdx++;
+ int readLen = buffer.remaining();
+ byte[] buf = new byte[readLen];
+ for (int i = 0; i < readLen; ++i) {
+ buf[i] = (byte) ('a' + (i % 26));
+
+ }
+ buffer.put(buf);
+ return readLen;
+ } else if (readIdx == 2) {
+ // packet
+ readIdx++;
+ serializer.writeInt3(10);
+ serializer.writeInt1(packetId++);
+
+ buffer.put(serializer.toArray());
+ return 4;
+ } else if (readIdx == 3) {
+ readIdx++;
+ int readLen = buffer.remaining();
+ byte[] buf = new byte[readLen];
+ for (int i = 0; i < readLen; ++i) {
+ buf[i] = (byte) ('a' + (maxLen + i) % 26);
+
+ }
+ buffer.put(buf);
+ return readLen;
+ }
+ return 0;
}
- buffer.put(buf);
- return readLen;
- }
- return 0;
+ };
}
-
- }).anyTimes();
- EasyMock.replay(channel);
+ };
MysqlChannel channel1 = new MysqlChannel(channel);
@@ -141,52 +156,56 @@ public class MysqlChannelTest {
@Test(expected = IOException.class)
public void testBadSeq() throws IOException {
// mock
-
EasyMock.expect(channel.read(EasyMock.anyObject(ByteBuffer.class))).andDelegateTo(new
WrapperSocketChannel() {
- @Override
- public int read(ByteBuffer buffer) {
- int maxLen = 0xffffff - 1;
- MysqlSerializer serializer = MysqlSerializer.newInstance();
- if (readIdx == 0) {
- // packet
- readIdx++;
- serializer.writeInt3(maxLen);
- serializer.writeInt1(packetId++);
-
- buffer.put(serializer.toArray());
- return 4;
- } else if (readIdx == 1) {
- readIdx++;
- int readLen = buffer.remaining();
- byte[] buf = new byte[readLen];
- for (int i = 0; i < readLen; ++i) {
- buf[i] = (byte) ('a' + (i % 26));
-
+ new Expectations() {
+ {
+ channel.read((ByteBuffer) any);
+ minTimes = 0;
+ result = new Delegate() {
+ int fakeRead(ByteBuffer buffer) {
+ int maxLen = 0xffffff - 1;
+ MysqlSerializer serializer =
MysqlSerializer.newInstance();
+ if (readIdx == 0) {
+ // packet
+ readIdx++;
+ serializer.writeInt3(maxLen);
+ serializer.writeInt1(packetId++);
+
+ buffer.put(serializer.toArray());
+ return 4;
+ } else if (readIdx == 1) {
+ readIdx++;
+ int readLen = buffer.remaining();
+ byte[] buf = new byte[readLen];
+ for (int i = 0; i < readLen; ++i) {
+ buf[i] = (byte) ('a' + (i % 26));
+
+ }
+ buffer.put(buf);
+ return readLen;
+ } else if (readIdx == 2) {
+ // packet
+ readIdx++;
+ serializer.writeInt3(10);
+ // NOTE: Bad packet seq
+ serializer.writeInt1(0);
+
+ buffer.put(serializer.toArray());
+ return 4;
+ } else if (readIdx == 3) {
+ readIdx++;
+ byte[] buf = new byte[buffer.remaining()];
+ for (int i = 0; i < buffer.remaining(); ++i) {
+ buf[i] = (byte) ('a' + (i % 26));
+
+ }
+ buffer.put(buf);
+ return buffer.remaining();
+ }
+ return 0;
}
- buffer.put(buf);
- return readLen;
- } else if (readIdx == 2) {
- // packet
- readIdx++;
- serializer.writeInt3(10);
- // NOTE: Bad packet seq
- serializer.writeInt1(0);
-
- buffer.put(serializer.toArray());
- return 4;
- } else if (readIdx == 3) {
- readIdx++;
- byte[] buf = new byte[buffer.remaining()];
- for (int i = 0; i < buffer.remaining(); ++i) {
- buf[i] = (byte) ('a' + (i % 26));
-
- }
- buffer.put(buf);
- return buffer.remaining();
- }
- return 0;
+ };
}
- }).anyTimes();
- EasyMock.replay(channel);
+ };
MysqlChannel channel1 = new MysqlChannel(channel);
@@ -196,8 +215,13 @@ public class MysqlChannelTest {
@Test(expected = IOException.class)
public void testException() throws IOException {
// mock
-
EasyMock.expect(channel.read(EasyMock.anyObject(ByteBuffer.class))).andThrow(new
IOException()).anyTimes();
- EasyMock.replay(channel);
+ new Expectations() {
+ {
+ channel.read((ByteBuffer) any);
+ minTimes = 0;
+ result = new IOException();
+ }
+ };
MysqlChannel channel1 = new MysqlChannel(channel);
@@ -208,16 +232,21 @@ public class MysqlChannelTest {
@Test
public void testSend() throws IOException {
// mock
-
EasyMock.expect(channel.write(EasyMock.anyObject(ByteBuffer.class))).andDelegateTo(new
WrapperSocketChannel() {
- @Override
- public int write(ByteBuffer buffer) {
+ new Expectations() {
+ {
+ channel.write((ByteBuffer) any);
+ minTimes = 0;
+ result = new Delegate() {
+ int fakeWrite(ByteBuffer buffer) {
int writeLen = 0;
writeLen += buffer.remaining();
buffer.position(buffer.limit());
return writeLen;
}
- }).anyTimes();
- EasyMock.replay(channel);
+ };
+ }
+ };
+
MysqlChannel channel1 = new MysqlChannel(channel);
ByteBuffer buf = ByteBuffer.allocate(1000);
channel1.sendOnePacket(buf);
@@ -229,8 +258,13 @@ public class MysqlChannelTest {
@Test(expected = IOException.class)
public void testSendException() throws IOException {
// mock
-
EasyMock.expect(channel.write(EasyMock.anyObject(ByteBuffer.class))).andThrow(new
IOException()).anyTimes();
- EasyMock.replay(channel);
+ new Expectations() {
+ {
+ channel.write((ByteBuffer) any);
+ minTimes = 0;
+ result = new IOException();
+ }
+ };
MysqlChannel channel1 = new MysqlChannel(channel);
ByteBuffer buf = ByteBuffer.allocate(1000);
channel1.sendOnePacket(buf);
@@ -242,17 +276,20 @@ public class MysqlChannelTest {
@Test(expected = IOException.class)
public void testSendFail() throws IOException {
// mock
-
EasyMock.expect(channel.write(EasyMock.anyObject(ByteBuffer.class))).andDelegateTo(new
WrapperSocketChannel() {
- @Override
- public int write(ByteBuffer buffer) {
+ new Expectations() {
+ {
+ channel.write((ByteBuffer) any);
+ minTimes = 0;
+ result = new Delegate() {
+ int fakeWrite(ByteBuffer buffer) {
int writeLen = 0;
writeLen += buffer.remaining();
buffer.position(buffer.limit());
return writeLen - 1;
}
-
- }).anyTimes();
- EasyMock.replay(channel);
+ };
+ }
+ };
MysqlChannel channel1 = new MysqlChannel(channel);
ByteBuffer buf = ByteBuffer.allocate(1000);
channel1.sendAndFlush(buf);
diff --git
a/fe/src/test/java/org/apache/doris/mysql/MysqlHandshakePacketTest.java
b/fe/src/test/java/org/apache/doris/mysql/MysqlHandshakePacketTest.java
index 034734c..86ea229 100644
--- a/fe/src/test/java/org/apache/doris/mysql/MysqlHandshakePacketTest.java
+++ b/fe/src/test/java/org/apache/doris/mysql/MysqlHandshakePacketTest.java
@@ -18,34 +18,35 @@
package org.apache.doris.mysql;
import com.google.common.primitives.Bytes;
+import mockit.Expectations;
+import mockit.Mocked;
import org.junit.Assert;
-import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.api.easymock.PowerMock;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
import java.nio.ByteBuffer;
-@RunWith(PowerMockRunner.class)
-@PowerMockIgnore({ "org.apache.log4j.*", "javax.management.*" })
-@PrepareForTest({MysqlPassword.class})
public class MysqlHandshakePacketTest {
private byte[] buf;
private MysqlCapability capability;
+ @Mocked
+ MysqlPassword mysqlPassword;
+
@Before
public void setUp() {
buf = new byte[20];
for (int i = 0; i < 20; ++i) {
buf[i] = (byte) ('a' + i);
}
- PowerMock.mockStatic(MysqlPassword.class);
-
EasyMock.expect(MysqlPassword.createRandomString(20)).andReturn(buf).anyTimes();
- PowerMock.replay(MysqlPassword.class);
+
+ new Expectations() {
+ {
+ MysqlPassword.createRandomString(20);
+ minTimes = 0;
+ result = buf;
+ }
+ };
capability = new MysqlCapability(0);
}
diff --git a/fe/src/test/java/org/apache/doris/mysql/MysqlProtoTest.java
b/fe/src/test/java/org/apache/doris/mysql/MysqlProtoTest.java
index 90bcc29..eddc4c4 100644
--- a/fe/src/test/java/org/apache/doris/mysql/MysqlProtoTest.java
+++ b/fe/src/test/java/org/apache/doris/mysql/MysqlProtoTest.java
@@ -17,87 +17,101 @@
package org.apache.doris.mysql;
+import mockit.Delegate;
+import mockit.Expectations;
+import mockit.Mocked;
import org.apache.doris.analysis.UserIdentity;
import org.apache.doris.catalog.Catalog;
import org.apache.doris.catalog.Database;
import org.apache.doris.common.DdlException;
import org.apache.doris.mysql.privilege.PaloAuth;
import org.apache.doris.mysql.privilege.PrivPredicate;
-import org.apache.doris.mysql.privilege.UserPropertyMgr;
import org.apache.doris.qe.ConnectContext;
-import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.api.easymock.PowerMock;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
import org.slf4j.Logger;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
-import java.nio.channels.SocketChannel;
import java.util.List;
-@RunWith(PowerMockRunner.class)
-@PowerMockIgnore({ "org.apache.log4j.*", "javax.management.*" })
-@PrepareForTest({Catalog.class, ConnectContext.class, MysqlPassword.class,
UserPropertyMgr.class})
public class MysqlProtoTest {
private static final Logger LOG =
org.slf4j.LoggerFactory.getLogger(MysqlProtoTest.class);
+ @Mocked
private MysqlChannel channel;
-
+ @Mocked
+ private MysqlPassword password;
+ @Mocked
private Catalog catalog;
+ @Mocked
+ private PaloAuth auth;
@Before
public void setUp() throws DdlException {
// mock auth
- PaloAuth auth = EasyMock.createMock(PaloAuth.class);
-
EasyMock.expect(auth.checkGlobalPriv(EasyMock.anyObject(ConnectContext.class),
-
EasyMock.anyObject(PrivPredicate.class))).andReturn(true).anyTimes();
-
- EasyMock.expect(auth.checkPassword(EasyMock.anyString(),
EasyMock.anyString(), (byte[]) EasyMock.anyObject(),
- (byte[]) EasyMock.anyObject(), (List<UserIdentity>)
EasyMock.anyObject())).andDelegateTo(
- new WrappedAuth() {
- @Override
- public boolean checkPassword(String remoteUser,
String remoteHost, byte[] remotePasswd,
- byte[] randomString,
- List<UserIdentity> currentUser) {
- UserIdentity userIdentity = new
UserIdentity("defaut_cluster:user", "192.168.1.1");
- currentUser.add(userIdentity);
- return true;
- }
- }).anyTimes();
- EasyMock.replay(auth);
-
- // Mock catalog
- catalog = EasyMock.createMock(Catalog.class);
-
EasyMock.expect(catalog.getDb(EasyMock.isA(String.class))).andReturn(new
Database()).anyTimes();
- EasyMock.expect(catalog.getAuth()).andReturn(auth).anyTimes();
- PowerMock.mockStatic(Catalog.class);
- EasyMock.expect(Catalog.getInstance()).andReturn(catalog).anyTimes();
-
EasyMock.expect(Catalog.getCurrentCatalog()).andReturn(catalog).anyTimes();
- catalog.changeDb(EasyMock.anyObject(ConnectContext.class),
EasyMock.anyString());
- EasyMock.expectLastCall().anyTimes();
-
- EasyMock.replay(catalog);
- PowerMock.replay(Catalog.class);
+ new Expectations() {
+ {
+ auth.checkGlobalPriv((ConnectContext) any, (PrivPredicate)
any);
+ minTimes = 0;
+ result = true;
+
+ auth.checkPassword(anyString, anyString, (byte[]) any,
(byte[]) any, (List<UserIdentity>) any);
+ minTimes = 0;
+ result = new Delegate() {
+ boolean fakeCheckPassword(String remoteUser, String
remoteHost, byte[] remotePasswd, byte[] randomString,
+ List<UserIdentity> currentUser) {
+ UserIdentity userIdentity = new
UserIdentity("defaut_cluster:user", "192.168.1.1");
+ currentUser.add(userIdentity);
+ return true;
+ }
+ };
+
+ catalog.getDb(anyString);
+ minTimes = 0;
+ result = new Database();
+
+ catalog.getAuth();
+ minTimes = 0;
+ result = auth;
+
+ catalog.changeDb((ConnectContext) any, anyString);
+ minTimes = 0;
+ }
+ };
+
+ new Expectations(catalog) {
+ {
+ Catalog.getInstance();
+ minTimes = 0;
+ result = catalog;
+
+ Catalog.getCurrentCatalog();
+ minTimes = 0;
+ result = catalog;
+ }
+ };
+
}
private void mockChannel(String user, boolean sendOk) throws Exception {
// mock channel
- channel = EasyMock.createMock(MysqlChannel.class);
- // channel.sendOnePacket(EasyMock.anyObject(ByteBuffer.class));
- channel.sendAndFlush(EasyMock.anyObject(ByteBuffer.class));
- if (sendOk) {
- EasyMock.expectLastCall().anyTimes();
- } else {
- EasyMock.expectLastCall().andThrow(new IOException()).anyTimes();
- }
+ new Expectations() {
+ {
+ channel.sendAndFlush((ByteBuffer) any);
+ minTimes = 0;
+ result = new Delegate() {
+ void sendAndFlush(ByteBuffer packet) throws IOException {
+ if (!sendOk) {
+ throw new IOException();
+ }
+ }
+ };
+ }
+ };
// mock auth packet
MysqlSerializer serializer = MysqlSerializer.newInstance();
@@ -123,25 +137,36 @@ public class MysqlProtoTest {
serializer.writeNulTerminateString("database");
ByteBuffer buffer = serializer.toByteBuffer();
- EasyMock.expect(channel.fetchOnePacket()).andReturn(buffer).anyTimes();
-
EasyMock.expect(channel.getRemoteIp()).andReturn("192.168.1.1").anyTimes();
- EasyMock.replay(channel);
-
- PowerMock.expectNew(MysqlChannel.class,
EasyMock.anyObject(SocketChannel.class)).andReturn(channel).anyTimes();
- PowerMock.replay(MysqlChannel.class);
+ new Expectations() {
+ {
+ channel.fetchOnePacket();
+ minTimes = 0;
+ result = buffer;
+
+ channel.getRemoteIp();
+ minTimes = 0;
+ result = "192.168.1.1";
+ }
+ };
}
- private void mockPassword(boolean result) {
+ private void mockPassword(boolean res) {
// mock password
- PowerMock.mockStatic(MysqlPassword.class);
- EasyMock.expect(MysqlPassword.checkScramble(
- EasyMock.anyObject(byte[].class),
EasyMock.anyObject(byte[].class),
- EasyMock.anyObject(byte[].class)))
- .andReturn(result).anyTimes();
- EasyMock.expect(MysqlPassword.createRandomString(20)).andReturn(new
byte[20]).anyTimes();
-
EasyMock.expect(MysqlPassword.getSaltFromPassword(EasyMock.isA(byte[].class)))
- .andReturn(new byte[20]).anyTimes();
- PowerMock.replay(MysqlPassword.class);
+ new Expectations(password) {
+ {
+ MysqlPassword.checkScramble((byte[]) any, (byte[]) any,
(byte[]) any);
+ minTimes = 0;
+ result = res;
+
+ MysqlPassword.createRandomString(20);
+ minTimes = 0;
+ result = new byte[20];
+
+ MysqlPassword.getSaltFromPassword((byte[]) any);
+ minTimes = 0;
+ result = new byte[20];
+ }
+ };
}
private void mockAccess() throws Exception {
diff --git a/fe/src/test/java/org/apache/doris/mysql/MysqlServerTest.java
b/fe/src/test/java/org/apache/doris/mysql/MysqlServerTest.java
index e2c8440..ebe720c 100644
--- a/fe/src/test/java/org/apache/doris/mysql/MysqlServerTest.java
+++ b/fe/src/test/java/org/apache/doris/mysql/MysqlServerTest.java
@@ -17,12 +17,13 @@
package org.apache.doris.mysql;
+import mockit.Delegate;
+import mockit.Expectations;
+import mockit.Mocked;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.ConnectScheduler;
import org.junit.Assert;
-import org.easymock.EasyMock;
-import org.easymock.IAnswer;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
@@ -38,17 +39,20 @@ public class MysqlServerTest {
private int submitNum;
private int submitFailNum;
+ @Mocked
private ConnectScheduler scheduler;
+ @Mocked
private ConnectScheduler badScheduler;
@Before
public void setUp() {
submitNum = 0;
submitFailNum = 0;
- scheduler = EasyMock.createMock(ConnectScheduler.class);
-
EasyMock.expect(scheduler.submit(EasyMock.anyObject(ConnectContext.class)))
- .andAnswer(new IAnswer<Boolean>() {
- @Override
+ new Expectations() {
+ {
+ scheduler.submit((ConnectContext) any);
+ minTimes = 0;
+ result = new Delegate() {
public Boolean answer() throws Throwable {
LOG.info("answer.");
synchronized (MysqlServerTest.this) {
@@ -56,13 +60,11 @@ public class MysqlServerTest {
}
return Boolean.TRUE;
}
- }).anyTimes();
- EasyMock.replay(scheduler);
+ };
- badScheduler = EasyMock.createMock(ConnectScheduler.class);
-
EasyMock.expect(badScheduler.submit(EasyMock.anyObject(ConnectContext.class)))
- .andAnswer(new IAnswer<Boolean>() {
- @Override
+ badScheduler.submit((ConnectContext) any);
+ minTimes = 0;
+ result = new Delegate() {
public Boolean answer() throws Throwable {
LOG.info("answer.");
synchronized (MysqlServerTest.this) {
@@ -70,8 +72,9 @@ public class MysqlServerTest {
}
return Boolean.FALSE;
}
- }).anyTimes();
- EasyMock.replay(badScheduler);
+ };
+ }
+ };
}
@Test
diff --git a/fe/src/test/java/org/apache/doris/qe/SimpleSchedulerTest.java
b/fe/src/test/java/org/apache/doris/qe/SimpleSchedulerTest.java
index 541f19b..0e822ba 100644
--- a/fe/src/test/java/org/apache/doris/qe/SimpleSchedulerTest.java
+++ b/fe/src/test/java/org/apache/doris/qe/SimpleSchedulerTest.java
@@ -17,6 +17,8 @@
package org.apache.doris.qe;
+import mockit.Expectations;
+import mockit.Mocked;
import org.apache.doris.catalog.Catalog;
import org.apache.doris.common.FeConstants;
import org.apache.doris.common.Reference;
@@ -28,46 +30,47 @@ import org.apache.doris.thrift.TScanRangeLocation;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
-import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.powermock.api.easymock.PowerMock;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-@RunWith(PowerMockRunner.class)
-@PowerMockIgnore("org.apache.log4j.*")
-@PrepareForTest(Catalog.class)
public class SimpleSchedulerTest {
static Reference<Long> ref = new Reference<Long>();
+ @Mocked
private Catalog catalog;
+ @Mocked
private EditLog editLog;
@Before
public void setUp() {
- editLog = EasyMock.createMock(EditLog.class);
- editLog.logAddBackend(EasyMock.anyObject(Backend.class));
- EasyMock.expectLastCall().anyTimes();
- editLog.logDropBackend(EasyMock.anyObject(Backend.class));
- EasyMock.expectLastCall().anyTimes();
- editLog.logBackendStateChange(EasyMock.anyObject(Backend.class));
- EasyMock.expectLastCall().anyTimes();
- EasyMock.replay(editLog);
-
- catalog = EasyMock.createMock(Catalog.class);
- EasyMock.expect(catalog.getEditLog()).andReturn(editLog).anyTimes();
- EasyMock.replay(catalog);
-
- PowerMock.mockStatic(Catalog.class);
- EasyMock.expect(Catalog.getInstance()).andReturn(catalog).anyTimes();
- PowerMock.replay(Catalog.class);
+ new Expectations() {
+ {
+ editLog.logAddBackend((Backend) any);
+ minTimes = 0;
+
+ editLog.logDropBackend((Backend) any);
+ minTimes = 0;
+
+ editLog.logBackendStateChange((Backend) any);
+ minTimes = 0;
+
+ catalog.getEditLog();
+ minTimes = 0;
+ result = editLog;
+ }
+ };
+
+ new Expectations(catalog) {
+ {
+ Catalog.getInstance();
+ minTimes = 0;
+ result = catalog;
+ }
+ };
}
// TODO(lingbin): PALO-2051.
diff --git a/fe/src/test/java/org/apache/doris/task/LoadEtlTaskTest.java
b/fe/src/test/java/org/apache/doris/task/LoadEtlTaskTest.java
index 392d6ce..d774a23 100644
--- a/fe/src/test/java/org/apache/doris/task/LoadEtlTaskTest.java
+++ b/fe/src/test/java/org/apache/doris/task/LoadEtlTaskTest.java
@@ -17,6 +17,8 @@
package org.apache.doris.task;
+import mockit.Expectations;
+import mockit.Mocked;
import org.apache.doris.catalog.Catalog;
import org.apache.doris.catalog.Database;
import org.apache.doris.catalog.MaterializedIndex;
@@ -26,7 +28,6 @@ import org.apache.doris.catalog.Partition;
import org.apache.doris.catalog.Tablet;
import org.apache.doris.common.Config;
import org.apache.doris.common.util.UnitTestUtil;
-import org.apache.doris.load.DppConfig;
import org.apache.doris.load.DppScheduler;
import org.apache.doris.load.EtlStatus;
import org.apache.doris.load.Load;
@@ -42,15 +43,9 @@ import org.apache.doris.thrift.TEtlState;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.api.easymock.PowerMock;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
import java.util.ArrayList;
import java.util.HashMap;
@@ -58,9 +53,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({ HadoopLoadEtlTask.class, Catalog.class })
-@PowerMockIgnore("javax.management.*")
public class LoadEtlTaskTest {
private long dbId;
private long tableId;
@@ -70,8 +62,11 @@ public class LoadEtlTaskTest {
private long backendId;
private String label;
-
+ @Mocked
private Catalog catalog;
+ @Mocked
+ private EditLog editLog;
+ @Mocked
private Load load;
private Database db;
@@ -90,20 +85,28 @@ public class LoadEtlTaskTest {
}
@Test
- public void testRunEtlTask() throws Exception {
+ public void testRunEtlTask(@Mocked DppScheduler dppScheduler) throws
Exception {
// mock catalog
db = UnitTestUtil.createDb(dbId, tableId, paritionId, indexId,
tabletId, backendId, 1L, 0L);
- catalog = EasyMock.createNiceMock(Catalog.class);
- EasyMock.expect(catalog.getDb(dbId)).andReturn(db).anyTimes();
-
EasyMock.expect(catalog.getDb(db.getFullName())).andReturn(db).anyTimes();
- // mock editLog
- EditLog editLog = EasyMock.createMock(EditLog.class);
- EasyMock.expect(catalog.getEditLog()).andReturn(editLog).anyTimes();
- // mock static getInstance
- PowerMock.mockStatic(Catalog.class);
- EasyMock.expect(Catalog.getInstance()).andReturn(catalog).anyTimes();
- PowerMock.replay(Catalog.class);
-
+ new Expectations(catalog) {
+ {
+ catalog.getDb(dbId);
+ minTimes = 0;
+ result = db;
+
+ catalog.getDb(db.getFullName());
+ minTimes = 0;
+ result = db;
+
+ catalog.getEditLog();
+ minTimes = 0;
+ result = editLog;
+
+ Catalog.getInstance();
+ minTimes = 0;
+ result = catalog;
+ }
+ };
// create job
LoadJob job = new LoadJob(label);
job.setState(JobState.ETL);
@@ -126,36 +129,52 @@ public class LoadEtlTaskTest {
job.setIdToTableLoadInfo(idToTableLoadInfo);
// mock load
- load = EasyMock.createMock(Load.class);
-
EasyMock.expect(load.addLoadingPartitions(EasyMock.isA(Set.class))).andReturn(true).times(1);
- EasyMock.expect(load.updateLoadJobState(job,
JobState.LOADING)).andReturn(true).times(1);
- EasyMock.replay(load);
- EasyMock.expect(catalog.getLoadInstance()).andReturn(load).times(1);
- EasyMock.replay(catalog);
+ new Expectations() {
+ {
+ load.addLoadingPartitions((Set) any);
+ minTimes = 0;
+ result = true;
+
+ load.updateLoadJobState(job, JobState.LOADING);
+ times = 1;
+ result = true;
+
+ catalog.getLoadInstance();
+ times = 1;
+ result = load;
+ }
+ };
// mock dppscheduler
- DppScheduler dppScheduler = EasyMock.createMock(DppScheduler.class);
EtlStatus runningStatus = new EtlStatus();
runningStatus.setState(TEtlState.RUNNING);
Map<String, String> stats = Maps.newHashMap();
stats.put("map() completion", "1");
stats.put("reduce() completion", "0.2");
runningStatus.setStats(stats);
-
EasyMock.expect(dppScheduler.getEtlJobStatus(EasyMock.anyString())).andReturn(runningStatus).times(1);
+
EtlStatus finishedStatus = new EtlStatus();
finishedStatus.setState(TEtlState.FINISHED);
Map<String, String> counters = Maps.newHashMap();
counters.put("dpp.norm.ALL", "100");
counters.put("dpp.abnorm.ALL", "0");
finishedStatus.setCounters(counters);
-
EasyMock.expect(dppScheduler.getEtlJobStatus(EasyMock.anyString())).andReturn(finishedStatus).times(1);
+
Map<String, Long> etlFiles = Maps.newHashMap();
etlFiles.put("label_0.0.0.0", 1L);
-
EasyMock.expect(dppScheduler.getEtlFiles(EasyMock.anyString())).andReturn(etlFiles).times(1);
- EasyMock.replay(dppScheduler);
- PowerMock.expectNew(DppScheduler.class,
EasyMock.anyObject(DppConfig.class)).andReturn(dppScheduler).times(3);
- PowerMock.replay(DppScheduler.class);
-
+
+ new Expectations() {
+ {
+ dppScheduler.getEtlJobStatus(anyString);
+ times = 2;
+ returns(runningStatus, finishedStatus);
+
+ dppScheduler.getEtlFiles(anyString);
+ times = 1;
+ result = etlFiles;
+ }
+ };
+
// test exec: running
HadoopLoadEtlTask loadEtlTask = new HadoopLoadEtlTask(job);
loadEtlTask.exec();
diff --git a/fe/src/test/java/org/apache/doris/task/LoadPendingTaskTest.java
b/fe/src/test/java/org/apache/doris/task/LoadPendingTaskTest.java
index 1c15abc..b5b4410 100644
--- a/fe/src/test/java/org/apache/doris/task/LoadPendingTaskTest.java
+++ b/fe/src/test/java/org/apache/doris/task/LoadPendingTaskTest.java
@@ -17,6 +17,8 @@
package org.apache.doris.task;
+import mockit.Expectations;
+import mockit.Mocked;
import org.apache.doris.catalog.Catalog;
import org.apache.doris.catalog.Database;
import org.apache.doris.catalog.OlapTable;
@@ -36,23 +38,16 @@ import org.apache.doris.persist.EditLog;
import org.apache.doris.thrift.TStatus;
import org.apache.doris.thrift.TStatusCode;
-import org.easymock.EasyMock;
+import org.apache.doris.transaction.GlobalTransactionMgr;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.api.easymock.PowerMock;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({ HadoopLoadPendingTask.class, Catalog.class })
-@PowerMockIgnore("javax.management.*")
public class LoadPendingTaskTest {
private long dbId;
private long tableId;
@@ -62,9 +57,15 @@ public class LoadPendingTaskTest {
private long backendId;
private String label;
-
+ @Mocked
private Catalog catalog;
+ @Mocked
+ private EditLog editLog;
+ @Mocked
private Load load;
+ @Mocked
+ private DppScheduler dppScheduler;
+
private Database db;
@Before
@@ -84,16 +85,34 @@ public class LoadPendingTaskTest {
public void testRunPendingTask() throws Exception {
// mock catalog
db = UnitTestUtil.createDb(dbId, tableId, partitionId, indexId,
tabletId, backendId, 1L, 0L);
- catalog = EasyMock.createNiceMock(Catalog.class);
- EasyMock.expect(catalog.getDb(dbId)).andReturn(db).anyTimes();
-
EasyMock.expect(catalog.getDb(db.getFullName())).andReturn(db).anyTimes();
- // mock editLog
- EditLog editLog = EasyMock.createMock(EditLog.class);
- EasyMock.expect(catalog.getEditLog()).andReturn(editLog).anyTimes();
- // mock static getInstance
- PowerMock.mockStatic(Catalog.class);
- EasyMock.expect(Catalog.getInstance()).andReturn(catalog).anyTimes();
- PowerMock.replay(Catalog.class);
+
+ GlobalTransactionMgr globalTransactionMgr = new
GlobalTransactionMgr(catalog);
+ globalTransactionMgr.setEditLog(editLog);
+
+ // mock catalog
+ new Expectations(catalog) {
+ {
+ catalog.getDb(dbId);
+ minTimes = 0;
+ result = db;
+
+ catalog.getDb(db.getFullName());
+ minTimes = 0;
+ result = db;
+
+ catalog.getEditLog();
+ minTimes = 0;
+ result = editLog;
+
+ Catalog.getInstance();
+ minTimes = 0;
+ result = catalog;
+
+ Catalog.getCurrentGlobalTransactionMgr();
+ minTimes = 0;
+ result = globalTransactionMgr;
+ }
+ };
// create job
LoadJob job = new LoadJob(label);
@@ -103,6 +122,7 @@ public class LoadPendingTaskTest {
job.setClusterInfo(cluster, Load.clusterToDppConfig.get(cluster));
// set partition load infos
OlapTable table = (OlapTable) db.getTable(tableId);
+ table.setBaseIndexId(0L);
Partition partition = table.getPartition(partitionId);
Source source = new Source(new ArrayList<String>());
List<Source> sources = new ArrayList<Source>();
@@ -115,22 +135,36 @@ public class LoadPendingTaskTest {
Map<Long, TableLoadInfo> idToTableLoadInfo = new HashMap<Long,
TableLoadInfo>();
idToTableLoadInfo.put(tableId, tableLoadInfo);
job.setIdToTableLoadInfo(idToTableLoadInfo);
+ job.setTimeoutSecond(10);
- // mock load
- load = EasyMock.createMock(Load.class);
- EasyMock.expect(load.updateLoadJobState(job,
JobState.ETL)).andReturn(true).times(1);
- EasyMock.expect(load.getLoadErrorHubInfo()).andReturn(null).times(1);
- EasyMock.replay(load);
- EasyMock.expect(catalog.getLoadInstance()).andReturn(load).times(1);
- EasyMock.replay(catalog);
-
- // mock dppscheduler
- DppScheduler dppScheduler = EasyMock.createMock(DppScheduler.class);
- EasyMock.expect(dppScheduler.submitEtlJob(EasyMock.anyLong(),
EasyMock.anyString(), EasyMock.anyString(),
- EasyMock.anyString(),
EasyMock.isA(Map.class), EasyMock.anyInt()))
- .andReturn(new EtlSubmitResult(new TStatus(TStatusCode.OK),
"job_123456")).times(1);
- EasyMock.replay(dppScheduler);
- PowerMock.expectNew(DppScheduler.class,
EasyMock.anyObject(DppConfig.class)).andReturn(dppScheduler).times(1);
- PowerMock.replay(DppScheduler.class);
+ // mock
+ new Expectations() {
+ {
+ load.updateLoadJobState(job, JobState.ETL);
+ times = 1;
+ result = true;
+
+ load.getLoadErrorHubInfo();
+ times = 1;
+ result = null;
+
+ catalog.getLoadInstance();
+ times = 1;
+ result = load;
+
+ dppScheduler.submitEtlJob(anyLong, anyString, anyString,
anyString, (Map) any, anyInt);
+ times = 1;
+ result = new EtlSubmitResult(new TStatus(TStatusCode.OK),
"job_123456");
+
+ editLog.logSaveTransactionId(anyLong);
+ minTimes = 0;
+ }
+ };
+
+ HadoopLoadPendingTask loadPendingTask = new HadoopLoadPendingTask(job);
+ loadPendingTask.exec();
+
+ Assert.assertEquals(job.getId(), loadPendingTask.getSignature());
+ Assert.assertEquals(JobState.PENDING, job.getState());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]