mirror of https://github.com/apache/lucene.git
SOLR-9966: Convert/migrate tests using EasyMock to Mockito
This commit is contained in:
parent
68d488431d
commit
46ef9256b4
|
@ -255,7 +255,6 @@ org.codehaus.janino.version = 2.7.6
|
||||||
|
|
||||||
/org.codehaus.woodstox/stax2-api = 3.1.4
|
/org.codehaus.woodstox/stax2-api = 3.1.4
|
||||||
/org.codehaus.woodstox/woodstox-core-asl = 4.4.1
|
/org.codehaus.woodstox/woodstox-core-asl = 4.4.1
|
||||||
/org.easymock/easymock = 3.0
|
|
||||||
|
|
||||||
org.eclipse.jetty.version = 9.3.14.v20161028
|
org.eclipse.jetty.version = 9.3.14.v20161028
|
||||||
/org.eclipse.jetty/jetty-continuation = ${org.eclipse.jetty.version}
|
/org.eclipse.jetty/jetty-continuation = ${org.eclipse.jetty.version}
|
||||||
|
|
|
@ -217,6 +217,8 @@ Other Changes
|
||||||
* SOLR-9890: factor out ShardResultTransformerUtils.[un]marshSortValue methods
|
* SOLR-9890: factor out ShardResultTransformerUtils.[un]marshSortValue methods
|
||||||
(Judith Silverman, Christine Poerschke)
|
(Judith Silverman, Christine Poerschke)
|
||||||
|
|
||||||
|
* SOLR-9966: Convert/migrate tests using EasyMock to Mockito (Cao Manh Dat, Uwe Schindler)
|
||||||
|
|
||||||
================== 6.4.2 ==================
|
================== 6.4.2 ==================
|
||||||
|
|
||||||
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
||||||
|
|
|
@ -521,33 +521,6 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
This product includes tests written with EasyMock Copyright 2001-2007
|
|
||||||
Tammo Freese (http://www.easymock.org/)
|
|
||||||
|
|
||||||
==========================================================================
|
|
||||||
The following license applies to easymock-2.2.jar
|
|
||||||
--------------------------------------------------------------------------
|
|
||||||
EasyMock 2 License (MIT License)
|
|
||||||
Copyright (c) 2001-2007 OFFIS, Tammo Freese.
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
|
||||||
the Software without restriction, including without limitation the rights to
|
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
||||||
of the Software, and to permit persons to whom the Software is furnished to do
|
|
||||||
so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
=========================================================================
|
=========================================================================
|
||||||
== Restlet Notice ==
|
== Restlet Notice ==
|
||||||
=========================================================================
|
=========================================================================
|
||||||
|
|
|
@ -25,8 +25,10 @@
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency org="hsqldb" name="hsqldb" rev="${/hsqldb/hsqldb}" conf="test"/>
|
<dependency org="hsqldb" name="hsqldb" rev="${/hsqldb/hsqldb}" conf="test"/>
|
||||||
<dependency org="org.apache.derby" name="derby" rev="${/org.apache.derby/derby}" conf="test"/>
|
<dependency org="org.apache.derby" name="derby" rev="${/org.apache.derby/derby}" conf="test"/>
|
||||||
<dependency org="org.easymock" name="easymock" rev="${/org.easymock/easymock}" conf="test"/>
|
|
||||||
|
|
||||||
|
<dependency org="org.mockito" name="mockito-core" rev="${/org.mockito/mockito-core}" conf="test"/>
|
||||||
|
<dependency org="net.bytebuddy" name="byte-buddy" rev="${/net.bytebuddy/byte-buddy}" conf="test"/>
|
||||||
|
<dependency org="org.objenesis" name="objenesis" rev="${/org.objenesis/objenesis}" conf="test"/>
|
||||||
<exclude org="*" ext="*" matcher="regexp" type="${ivy.exclude.types}"/>
|
<exclude org="*" ext="*" matcher="regexp" type="${ivy.exclude.types}"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</ivy-module>
|
</ivy-module>
|
||||||
|
|
|
@ -23,33 +23,21 @@ import java.util.Map;
|
||||||
import javax.naming.NamingException;
|
import javax.naming.NamingException;
|
||||||
import javax.naming.spi.InitialContextFactory;
|
import javax.naming.spi.InitialContextFactory;
|
||||||
|
|
||||||
import org.easymock.EasyMock;
|
import static org.mockito.Mockito.*;
|
||||||
import org.easymock.IAnswer;
|
|
||||||
import org.easymock.IMocksControl;
|
|
||||||
|
|
||||||
public class MockInitialContextFactory implements InitialContextFactory {
|
public class MockInitialContextFactory implements InitialContextFactory {
|
||||||
private static final Map<String, Object> objects = new HashMap<>();
|
private static final Map<String, Object> objects = new HashMap<>();
|
||||||
private final IMocksControl mockControl;
|
|
||||||
private final javax.naming.Context context;
|
private final javax.naming.Context context;
|
||||||
|
|
||||||
public MockInitialContextFactory() {
|
public MockInitialContextFactory() {
|
||||||
mockControl = EasyMock.createStrictControl();
|
context = mock(javax.naming.Context.class);
|
||||||
context = mockControl.createMock(javax.naming.Context.class);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
EasyMock.expect(context.lookup((String) EasyMock.anyObject())).andAnswer(
|
when(context.lookup(anyString())).thenAnswer(invocation -> objects.get(invocation.getArgument(0)));
|
||||||
new IAnswer<Object>() {
|
|
||||||
@Override
|
|
||||||
public Object answer() throws Throwable {
|
|
||||||
return objects.get(EasyMock.getCurrentArguments()[0]);
|
|
||||||
}
|
|
||||||
}).anyTimes();
|
|
||||||
|
|
||||||
} catch (NamingException e) {
|
} catch (NamingException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
mockControl.replay();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -35,13 +35,10 @@ import java.util.Properties;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.apache.lucene.util.Constants;
|
|
||||||
import org.apache.solr.handler.dataimport.JdbcDataSource.ResultSetIterator;
|
import org.apache.solr.handler.dataimport.JdbcDataSource.ResultSetIterator;
|
||||||
import org.easymock.EasyMock;
|
import static org.mockito.Mockito.*;
|
||||||
import org.easymock.IMocksControl;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -60,7 +57,6 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
private Driver driver;
|
private Driver driver;
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
private IMocksControl mockControl;
|
|
||||||
private JdbcDataSource jdbcDataSource = new JdbcDataSource();
|
private JdbcDataSource jdbcDataSource = new JdbcDataSource();
|
||||||
List<Map<String, String>> fields = new ArrayList<>();
|
List<Map<String, String>> fields = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -71,11 +67,6 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
|
|
||||||
String sysProp = System.getProperty("java.naming.factory.initial");
|
String sysProp = System.getProperty("java.naming.factory.initial");
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void beforeClass() throws Exception {
|
|
||||||
assumeFalse("SOLR-9893: EasyMock does not work with Java 9", Constants.JRE_IS_MINIMUM_JAVA9);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
@ -83,10 +74,9 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
System.setProperty("java.naming.factory.initial",
|
System.setProperty("java.naming.factory.initial",
|
||||||
MockInitialContextFactory.class.getName());
|
MockInitialContextFactory.class.getName());
|
||||||
|
|
||||||
mockControl = EasyMock.createStrictControl();
|
driver = mock(Driver.class);
|
||||||
driver = mockControl.createMock(Driver.class);
|
dataSource = mock(DataSource.class);
|
||||||
dataSource = mockControl.createMock(DataSource.class);
|
connection = mock(Connection.class);
|
||||||
connection = mockControl.createMock(Connection.class);
|
|
||||||
props.clear();
|
props.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +89,7 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
System.setProperty("java.naming.factory.initial", sysProp);
|
System.setProperty("java.naming.factory.initial", sysProp);
|
||||||
}
|
}
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
mockControl.reset();
|
reset(driver, dataSource, connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -108,16 +98,13 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
|
|
||||||
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
||||||
|
|
||||||
EasyMock.expect(dataSource.getConnection()).andReturn(connection);
|
when(dataSource.getConnection()).thenReturn(connection);
|
||||||
connection.setAutoCommit(false);
|
|
||||||
// connection.setHoldability(1);
|
|
||||||
|
|
||||||
mockControl.replay();
|
|
||||||
|
|
||||||
Connection conn = jdbcDataSource.createConnectionFactory(context, props)
|
Connection conn = jdbcDataSource.createConnectionFactory(context, props)
|
||||||
.call();
|
.call();
|
||||||
|
|
||||||
mockControl.verify();
|
verify(connection).setAutoCommit(false);
|
||||||
|
verify(dataSource).getConnection();
|
||||||
|
|
||||||
assertSame("connection", conn, connection);
|
assertSame("connection", conn, connection);
|
||||||
}
|
}
|
||||||
|
@ -131,17 +118,15 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
props.put("password", "4r3d");
|
props.put("password", "4r3d");
|
||||||
props.put("holdability", "HOLD_CURSORS_OVER_COMMIT");
|
props.put("holdability", "HOLD_CURSORS_OVER_COMMIT");
|
||||||
|
|
||||||
EasyMock.expect(dataSource.getConnection("Fred", "4r3d")).andReturn(
|
when(dataSource.getConnection("Fred", "4r3d")).thenReturn(
|
||||||
connection);
|
connection);
|
||||||
connection.setAutoCommit(false);
|
|
||||||
connection.setHoldability(1);
|
|
||||||
|
|
||||||
mockControl.replay();
|
|
||||||
|
|
||||||
Connection conn = jdbcDataSource.createConnectionFactory(context, props)
|
Connection conn = jdbcDataSource.createConnectionFactory(context, props)
|
||||||
.call();
|
.call();
|
||||||
|
|
||||||
mockControl.verify();
|
verify(connection).setAutoCommit(false);
|
||||||
|
verify(connection).setHoldability(1);
|
||||||
|
verify(dataSource).getConnection("Fred", "4r3d");
|
||||||
|
|
||||||
assertSame("connection", conn, connection);
|
assertSame("connection", conn, connection);
|
||||||
}
|
}
|
||||||
|
@ -161,7 +146,7 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
props.put("encryptKeyFile", "${" +propsNamespace +".encryptKeyFile}");
|
props.put("encryptKeyFile", "${" +propsNamespace +".encryptKeyFile}");
|
||||||
props.put("password", "${" +propsNamespace +".password}");
|
props.put("password", "${" +propsNamespace +".password}");
|
||||||
|
|
||||||
EasyMock.expect(dataSource.getConnection(user, plainPassword)).andReturn(
|
when(dataSource.getConnection(user, plainPassword)).thenReturn(
|
||||||
connection);
|
connection);
|
||||||
|
|
||||||
Map<String,Object> values = new HashMap<>();
|
Map<String,Object> values = new HashMap<>();
|
||||||
|
@ -171,15 +156,10 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
context.getVariableResolver().addNamespace(propsNamespace, values);
|
context.getVariableResolver().addNamespace(propsNamespace, values);
|
||||||
|
|
||||||
jdbcDataSource.init(context, props);
|
jdbcDataSource.init(context, props);
|
||||||
|
|
||||||
connection.setAutoCommit(false);
|
|
||||||
//connection.setHoldability(1);
|
|
||||||
|
|
||||||
mockControl.replay();
|
|
||||||
|
|
||||||
Connection conn = jdbcDataSource.getConnection();
|
Connection conn = jdbcDataSource.getConnection();
|
||||||
|
|
||||||
mockControl.verify();
|
verify(connection).setAutoCommit(false);
|
||||||
|
verify(dataSource).getConnection(user, plainPassword);
|
||||||
|
|
||||||
assertSame("connection", conn, connection);
|
assertSame("connection", conn, connection);
|
||||||
}
|
}
|
||||||
|
@ -193,7 +173,7 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
properties.put("user", "Fred");
|
properties.put("user", "Fred");
|
||||||
properties.put("encryptKeyFile", "${foo.bar}");
|
properties.put("encryptKeyFile", "${foo.bar}");
|
||||||
properties.put("password", "U2FsdGVkX18QMjY0yfCqlfBMvAB4d3XkwY96L7gfO2o=");
|
properties.put("password", "U2FsdGVkX18QMjY0yfCqlfBMvAB4d3XkwY96L7gfO2o=");
|
||||||
EasyMock.expect(dataSource.getConnection("Fred", "MyPassword")).andReturn(
|
when(dataSource.getConnection("Fred", "MyPassword")).thenReturn(
|
||||||
connection);
|
connection);
|
||||||
|
|
||||||
Map<String,Object> values = new HashMap<>();
|
Map<String,Object> values = new HashMap<>();
|
||||||
|
@ -201,14 +181,10 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
context.getVariableResolver().addNamespace("foo", values);
|
context.getVariableResolver().addNamespace("foo", values);
|
||||||
|
|
||||||
jdbcDataSource.init(context, properties);
|
jdbcDataSource.init(context, properties);
|
||||||
|
|
||||||
connection.setAutoCommit(false);
|
|
||||||
|
|
||||||
mockControl.replay();
|
|
||||||
|
|
||||||
jdbcDataSource.getConnection();
|
jdbcDataSource.getConnection();
|
||||||
|
|
||||||
mockControl.verify();
|
verify(connection).setAutoCommit(false);
|
||||||
|
verify(dataSource).getConnection("Fred", "MyPassword");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -218,9 +194,7 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
||||||
|
|
||||||
SQLException sqlException = new SQLException("fake");
|
SQLException sqlException = new SQLException("fake");
|
||||||
EasyMock.expect(dataSource.getConnection()).andThrow(sqlException);
|
when(dataSource.getConnection()).thenThrow(sqlException);
|
||||||
|
|
||||||
mockControl.replay();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jdbcDataSource.createConnectionFactory(context, props).call();
|
jdbcDataSource.createConnectionFactory(context, props).call();
|
||||||
|
@ -228,7 +202,7 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
assertSame(sqlException, ex);
|
assertSame(sqlException, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
mockControl.verify();
|
verify(dataSource).getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -238,19 +212,17 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
||||||
|
|
||||||
SQLException sqlException = new SQLException("fake");
|
SQLException sqlException = new SQLException("fake");
|
||||||
EasyMock.expect(dataSource.getConnection()).andReturn(connection);
|
when(dataSource.getConnection()).thenReturn(connection);
|
||||||
connection.setAutoCommit(false);
|
doThrow(sqlException).when(connection).setAutoCommit(false);
|
||||||
EasyMock.expectLastCall().andThrow(sqlException);
|
|
||||||
connection.close();
|
|
||||||
mockControl.replay();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jdbcDataSource.createConnectionFactory(context, props).call();
|
jdbcDataSource.createConnectionFactory(context, props).call();
|
||||||
} catch (DataImportHandlerException ex) {
|
} catch (DataImportHandlerException ex) {
|
||||||
assertSame(sqlException, ex.getCause());
|
assertSame(sqlException, ex.getCause());
|
||||||
}
|
}
|
||||||
|
verify(dataSource).getConnection();
|
||||||
mockControl.verify();
|
verify(connection).setAutoCommit(false);
|
||||||
|
verify(connection).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -258,22 +230,15 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
|
MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
|
||||||
|
|
||||||
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
||||||
EasyMock.expect(dataSource.getConnection()).andReturn(connection);
|
when(dataSource.getConnection()).thenReturn(connection);
|
||||||
|
|
||||||
jdbcDataSource.init(context, props);
|
jdbcDataSource.init(context, props);
|
||||||
|
|
||||||
connection.setAutoCommit(false);
|
|
||||||
|
|
||||||
SQLException sqlException = new SQLException("fake");
|
SQLException sqlException = new SQLException("fake");
|
||||||
Statement statement = mockControl.createMock(Statement.class);
|
Statement statement = mock(Statement.class);
|
||||||
EasyMock.expect(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY))
|
when(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY))
|
||||||
.andReturn(statement);
|
.thenReturn(statement);
|
||||||
statement.setFetchSize(500);
|
when(statement.execute("query")).thenThrow(sqlException);
|
||||||
statement.setMaxRows(0);
|
|
||||||
EasyMock.expect(statement.execute("query")).andThrow(sqlException);
|
|
||||||
statement.close();
|
|
||||||
|
|
||||||
mockControl.replay();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jdbcDataSource.getData("query");
|
jdbcDataSource.getData("query");
|
||||||
|
@ -282,7 +247,13 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
assertSame(sqlException, ex.getCause());
|
assertSame(sqlException, ex.getCause());
|
||||||
}
|
}
|
||||||
|
|
||||||
mockControl.verify();
|
verify(dataSource).getConnection();
|
||||||
|
verify(connection).setAutoCommit(false);
|
||||||
|
verify(connection).createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||||
|
verify(statement).setFetchSize(500);
|
||||||
|
verify(statement).setMaxRows(0);
|
||||||
|
verify(statement).execute("query");
|
||||||
|
verify(statement).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -290,26 +261,26 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
|
MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
|
||||||
|
|
||||||
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
||||||
EasyMock.expect(dataSource.getConnection()).andReturn(connection);
|
when(dataSource.getConnection()).thenReturn(connection);
|
||||||
|
|
||||||
jdbcDataSource.init(context, props);
|
jdbcDataSource.init(context, props);
|
||||||
|
|
||||||
connection.setAutoCommit(false);
|
Statement statement = mock(Statement.class);
|
||||||
|
when(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY))
|
||||||
Statement statement = mockControl.createMock(Statement.class);
|
.thenReturn(statement);
|
||||||
EasyMock.expect(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY))
|
when(statement.execute("query")).thenReturn(false);
|
||||||
.andReturn(statement);
|
when(statement.getUpdateCount()).thenReturn(-1);
|
||||||
statement.setFetchSize(500);
|
|
||||||
statement.setMaxRows(0);
|
|
||||||
EasyMock.expect(statement.execute("query")).andReturn(false);
|
|
||||||
EasyMock.expect(statement.getUpdateCount()).andReturn(-1);
|
|
||||||
statement.close();
|
|
||||||
|
|
||||||
mockControl.replay();
|
|
||||||
|
|
||||||
jdbcDataSource.getData("query");
|
jdbcDataSource.getData("query");
|
||||||
|
|
||||||
mockControl.verify();
|
verify(dataSource).getConnection();
|
||||||
|
verify(connection).setAutoCommit(false);
|
||||||
|
verify(connection).createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||||
|
verify(statement).setFetchSize(500);
|
||||||
|
verify(statement).setMaxRows(0);
|
||||||
|
verify(statement).execute("query");
|
||||||
|
verify(statement).getUpdateCount();
|
||||||
|
verify(statement).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -318,26 +289,19 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
|
MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
|
||||||
|
|
||||||
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
||||||
EasyMock.expect(dataSource.getConnection()).andReturn(connection);
|
when(dataSource.getConnection()).thenReturn(connection);
|
||||||
|
|
||||||
jdbcDataSource.init(context, props);
|
jdbcDataSource.init(context, props);
|
||||||
|
|
||||||
connection.setAutoCommit(false);
|
Statement statement = mock(Statement.class);
|
||||||
|
when(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY))
|
||||||
Statement statement = mockControl.createMock(Statement.class);
|
.thenReturn(statement);
|
||||||
EasyMock.expect(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY))
|
when(statement.execute("query")).thenReturn(true);
|
||||||
.andReturn(statement);
|
ResultSet resultSet = mock(ResultSet.class);
|
||||||
statement.setFetchSize(500);
|
when(statement.getResultSet()).thenReturn(resultSet);
|
||||||
statement.setMaxRows(0);
|
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
|
||||||
EasyMock.expect(statement.execute("query")).andReturn(true);
|
when(resultSet.getMetaData()).thenReturn(metaData);
|
||||||
ResultSet resultSet = mockControl.createMock(ResultSet.class);
|
when(metaData.getColumnCount()).thenReturn(0);
|
||||||
EasyMock.expect(statement.getResultSet()).andReturn(resultSet);
|
|
||||||
ResultSetMetaData metaData = mockControl.createMock(ResultSetMetaData.class);
|
|
||||||
EasyMock.expect(resultSet.getMetaData()).andReturn(metaData);
|
|
||||||
EasyMock.expect(metaData.getColumnCount()).andReturn(0);
|
|
||||||
statement.close();
|
|
||||||
|
|
||||||
mockControl.replay();
|
|
||||||
|
|
||||||
Iterator<Map<String,Object>> data = jdbcDataSource.getData("query");
|
Iterator<Map<String,Object>> data = jdbcDataSource.getData("query");
|
||||||
|
|
||||||
|
@ -346,7 +310,16 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
|
|
||||||
data.hasNext();
|
data.hasNext();
|
||||||
|
|
||||||
mockControl.verify();
|
verify(dataSource).getConnection();
|
||||||
|
verify(connection).setAutoCommit(false);
|
||||||
|
verify(connection).createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||||
|
verify(statement).setFetchSize(500);
|
||||||
|
verify(statement).setMaxRows(0);
|
||||||
|
verify(statement).execute("query");
|
||||||
|
verify(statement).getResultSet();
|
||||||
|
verify(statement).close();
|
||||||
|
verify(resultSet).getMetaData();
|
||||||
|
verify(metaData).getColumnCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -355,34 +328,36 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
|
MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
|
||||||
|
|
||||||
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
||||||
EasyMock.expect(dataSource.getConnection()).andReturn(connection);
|
when(dataSource.getConnection()).thenReturn(connection);
|
||||||
|
|
||||||
jdbcDataSource.init(context, props);
|
jdbcDataSource.init(context, props);
|
||||||
|
|
||||||
connection.setAutoCommit(false);
|
Statement statement = mock(Statement.class);
|
||||||
|
when(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY))
|
||||||
Statement statement = mockControl.createMock(Statement.class);
|
.thenReturn(statement);
|
||||||
EasyMock.expect(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY))
|
when(statement.execute("query")).thenReturn(true);
|
||||||
.andReturn(statement);
|
ResultSet resultSet = mock(ResultSet.class);
|
||||||
statement.setFetchSize(500);
|
when(statement.getResultSet()).thenReturn(resultSet);
|
||||||
statement.setMaxRows(0);
|
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
|
||||||
EasyMock.expect(statement.execute("query")).andReturn(true);
|
when(resultSet.getMetaData()).thenReturn(metaData);
|
||||||
ResultSet resultSet = mockControl.createMock(ResultSet.class);
|
when(metaData.getColumnCount()).thenReturn(0);
|
||||||
EasyMock.expect(statement.getResultSet()).andReturn(resultSet);
|
|
||||||
ResultSetMetaData metaData = mockControl.createMock(ResultSetMetaData.class);
|
|
||||||
EasyMock.expect(resultSet.getMetaData()).andReturn(metaData);
|
|
||||||
EasyMock.expect(metaData.getColumnCount()).andReturn(0);
|
|
||||||
resultSet.close();
|
|
||||||
statement.close();
|
|
||||||
connection.commit();
|
|
||||||
connection.close();
|
|
||||||
|
|
||||||
mockControl.replay();
|
|
||||||
|
|
||||||
jdbcDataSource.getData("query");
|
jdbcDataSource.getData("query");
|
||||||
jdbcDataSource.close();
|
jdbcDataSource.close();
|
||||||
|
|
||||||
mockControl.verify();
|
verify(dataSource).getConnection();
|
||||||
|
verify(connection).setAutoCommit(false);
|
||||||
|
verify(connection).createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||||
|
verify(statement).setFetchSize(500);
|
||||||
|
verify(statement).setMaxRows(0);
|
||||||
|
verify(statement).execute("query");
|
||||||
|
verify(statement).getResultSet();
|
||||||
|
verify(resultSet).getMetaData();
|
||||||
|
verify(metaData).getColumnCount();
|
||||||
|
verify(resultSet).close();
|
||||||
|
verify(statement).close();
|
||||||
|
verify(connection).commit();
|
||||||
|
verify(connection).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -391,109 +366,95 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
|
MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
|
||||||
|
|
||||||
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
||||||
EasyMock.expect(dataSource.getConnection()).andReturn(connection);
|
when(dataSource.getConnection()).thenReturn(connection);
|
||||||
|
|
||||||
jdbcDataSource.init(context, props);
|
jdbcDataSource.init(context, props);
|
||||||
|
|
||||||
connection.setAutoCommit(false);
|
Statement statement = mock(Statement.class);
|
||||||
|
when(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY))
|
||||||
Statement statement = mockControl.createMock(Statement.class);
|
.thenReturn(statement);
|
||||||
EasyMock.expect(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY))
|
when(statement.execute("query")).thenReturn(true);
|
||||||
.andReturn(statement);
|
ResultSet resultSet = mock(ResultSet.class);
|
||||||
statement.setFetchSize(500);
|
when(statement.getResultSet()).thenReturn(resultSet);
|
||||||
statement.setMaxRows(0);
|
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
|
||||||
EasyMock.expect(statement.execute("query")).andReturn(true);
|
when(resultSet.getMetaData()).thenReturn(metaData);
|
||||||
ResultSet resultSet = mockControl.createMock(ResultSet.class);
|
when(metaData.getColumnCount()).thenReturn(0);
|
||||||
EasyMock.expect(statement.getResultSet()).andReturn(resultSet);
|
when(statement.execute("other query")).thenReturn(false);
|
||||||
ResultSetMetaData metaData = mockControl.createMock(ResultSetMetaData.class);
|
when(statement.getUpdateCount()).thenReturn(-1);
|
||||||
EasyMock.expect(resultSet.getMetaData()).andReturn(metaData);
|
|
||||||
EasyMock.expect(metaData.getColumnCount()).andReturn(0);
|
|
||||||
resultSet.close();
|
|
||||||
statement.close();
|
|
||||||
EasyMock.expect(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY))
|
|
||||||
.andReturn(statement);
|
|
||||||
statement.setFetchSize(500);
|
|
||||||
statement.setMaxRows(0);
|
|
||||||
EasyMock.expect(statement.execute("other query")).andReturn(false);
|
|
||||||
EasyMock.expect(statement.getUpdateCount()).andReturn(-1);
|
|
||||||
statement.close();
|
|
||||||
|
|
||||||
mockControl.replay();
|
|
||||||
|
|
||||||
jdbcDataSource.getData("query");
|
jdbcDataSource.getData("query");
|
||||||
jdbcDataSource.getData("other query");
|
jdbcDataSource.getData("other query");
|
||||||
|
|
||||||
mockControl.verify();
|
verify(dataSource).getConnection();
|
||||||
|
verify(connection).setAutoCommit(false);
|
||||||
|
verify(connection, times(2)).createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||||
|
verify(statement, times(2)).setFetchSize(500);
|
||||||
|
verify(statement, times(2)).setMaxRows(0);
|
||||||
|
verify(statement).execute("query");
|
||||||
|
verify(statement).getResultSet();
|
||||||
|
verify(resultSet).getMetaData();
|
||||||
|
verify(metaData).getColumnCount();
|
||||||
|
verify(resultSet).close();
|
||||||
|
verify(statement, times(2)).close();
|
||||||
|
verify(statement).execute("other query");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultipleResultsSets_UpdateCountUpdateCountResultSet() throws Exception {
|
public void testMultipleResultsSets_UpdateCountUpdateCountResultSet() throws Exception {
|
||||||
MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
|
MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
|
||||||
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
||||||
EasyMock.expect(dataSource.getConnection()).andReturn(connection);
|
when(dataSource.getConnection()).thenReturn(connection);
|
||||||
jdbcDataSource.init(context, props);
|
jdbcDataSource.init(context, props);
|
||||||
connection.setAutoCommit(false);
|
|
||||||
|
|
||||||
Statement statement = mockControl.createMock(Statement.class);
|
Statement statement = mock(Statement.class);
|
||||||
EasyMock.expect(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY))
|
when(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY))
|
||||||
.andReturn(statement);
|
.thenReturn(statement);
|
||||||
statement.setFetchSize(500);
|
when(statement.execute("query")).thenReturn(false);
|
||||||
statement.setMaxRows(0);
|
when(statement.getUpdateCount()).thenReturn(1);
|
||||||
EasyMock.expect(statement.execute("query")).andReturn(false);
|
when(statement.getMoreResults()).thenReturn(false).thenReturn(true);
|
||||||
EasyMock.expect(statement.getUpdateCount()).andReturn(1);
|
ResultSet resultSet = mock(ResultSet.class);
|
||||||
EasyMock.expect(statement.getMoreResults()).andReturn(false);
|
when(statement.getResultSet()).thenReturn(resultSet);
|
||||||
EasyMock.expect(statement.getUpdateCount()).andReturn(1);
|
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
|
||||||
EasyMock.expect(statement.getMoreResults()).andReturn(true);
|
when(resultSet.getMetaData()).thenReturn(metaData);
|
||||||
ResultSet resultSet = mockControl.createMock(ResultSet.class);
|
when(metaData.getColumnCount()).thenReturn(0);
|
||||||
EasyMock.expect(statement.getResultSet()).andReturn(resultSet);
|
|
||||||
ResultSetMetaData metaData = mockControl.createMock(ResultSetMetaData.class);
|
|
||||||
EasyMock.expect(resultSet.getMetaData()).andReturn(metaData);
|
|
||||||
EasyMock.expect(metaData.getColumnCount()).andReturn(0);
|
|
||||||
|
|
||||||
mockControl.replay();
|
|
||||||
|
|
||||||
final ResultSetIterator resultSetIterator = jdbcDataSource.new ResultSetIterator("query");
|
final ResultSetIterator resultSetIterator = jdbcDataSource.new ResultSetIterator("query");
|
||||||
assertSame(resultSet, resultSetIterator.getResultSet());
|
assertSame(resultSet, resultSetIterator.getResultSet());
|
||||||
|
|
||||||
mockControl.verify();
|
verify(connection).setAutoCommit(false);
|
||||||
|
verify(connection).createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||||
|
verify(statement).setFetchSize(500);
|
||||||
|
verify(statement).setMaxRows(0);
|
||||||
|
verify(statement).execute("query");
|
||||||
|
verify(statement, times(2)).getUpdateCount();
|
||||||
|
verify(statement, times(2)).getMoreResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultipleResultsSets_ResultSetResultSet() throws Exception {
|
public void testMultipleResultsSets_ResultSetResultSet() throws Exception {
|
||||||
MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
|
MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
|
||||||
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
||||||
EasyMock.expect(dataSource.getConnection()).andReturn(connection);
|
when(dataSource.getConnection()).thenReturn(connection);
|
||||||
jdbcDataSource.init(context, props);
|
jdbcDataSource.init(context, props);
|
||||||
connection.setAutoCommit(false);
|
connection.setAutoCommit(false);
|
||||||
|
|
||||||
Statement statement = mockControl.createMock(Statement.class);
|
Statement statement = mock(Statement.class);
|
||||||
EasyMock.expect(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY))
|
when(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY))
|
||||||
.andReturn(statement);
|
.thenReturn(statement);
|
||||||
statement.setFetchSize(500);
|
when(statement.execute("query")).thenReturn(true);
|
||||||
statement.setMaxRows(0);
|
ResultSet resultSet1 = mock(ResultSet.class);
|
||||||
EasyMock.expect(statement.execute("query")).andReturn(true);
|
ResultSet resultSet2 = mock(ResultSet.class);
|
||||||
ResultSet resultSet1 = mockControl.createMock(ResultSet.class);
|
when(statement.getResultSet()).thenReturn(resultSet1).thenReturn(resultSet2).thenReturn(null);
|
||||||
EasyMock.expect(statement.getResultSet()).andReturn(resultSet1);
|
when(statement.getMoreResults()).thenReturn(true).thenReturn(false);
|
||||||
ResultSetMetaData metaData1 = mockControl.createMock(ResultSetMetaData.class);
|
ResultSetMetaData metaData1 = mock(ResultSetMetaData.class);
|
||||||
EasyMock.expect(resultSet1.getMetaData()).andReturn(metaData1);
|
when(resultSet1.getMetaData()).thenReturn(metaData1);
|
||||||
EasyMock.expect(metaData1.getColumnCount()).andReturn(0);
|
when(metaData1.getColumnCount()).thenReturn(0);
|
||||||
EasyMock.expect(resultSet1.next()).andReturn(false);
|
when(resultSet1.next()).thenReturn(false);
|
||||||
resultSet1.close();
|
ResultSetMetaData metaData2 = mock(ResultSetMetaData.class);
|
||||||
EasyMock.expect(statement.getMoreResults()).andReturn(true);
|
when(resultSet2.getMetaData()).thenReturn(metaData2);
|
||||||
ResultSet resultSet2 = mockControl.createMock(ResultSet.class);
|
when(metaData2.getColumnCount()).thenReturn(0);
|
||||||
EasyMock.expect(statement.getResultSet()).andReturn(resultSet2);
|
when(resultSet2.next()).thenReturn(true).thenReturn(false);
|
||||||
ResultSetMetaData metaData2 = mockControl.createMock(ResultSetMetaData.class);
|
when(statement.getUpdateCount()).thenReturn(-1);
|
||||||
EasyMock.expect(resultSet2.getMetaData()).andReturn(metaData2);
|
|
||||||
EasyMock.expect(metaData2.getColumnCount()).andReturn(0);
|
|
||||||
EasyMock.expect(resultSet2.next()).andReturn(true);
|
|
||||||
EasyMock.expect(resultSet2.next()).andReturn(false);
|
|
||||||
resultSet2.close();
|
|
||||||
EasyMock.expect(statement.getMoreResults()).andReturn(false);
|
|
||||||
EasyMock.expect(statement.getUpdateCount()).andReturn(-1);
|
|
||||||
statement.close();
|
|
||||||
|
|
||||||
mockControl.replay();
|
|
||||||
|
|
||||||
final ResultSetIterator resultSetIterator = jdbcDataSource.new ResultSetIterator("query");
|
final ResultSetIterator resultSetIterator = jdbcDataSource.new ResultSetIterator("query");
|
||||||
assertSame(resultSet1, resultSetIterator.getResultSet());
|
assertSame(resultSet1, resultSetIterator.getResultSet());
|
||||||
|
@ -501,31 +462,43 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
assertSame(resultSet2, resultSetIterator.getResultSet());
|
assertSame(resultSet2, resultSetIterator.getResultSet());
|
||||||
assertFalse(resultSetIterator.hasnext());
|
assertFalse(resultSetIterator.hasnext());
|
||||||
|
|
||||||
mockControl.verify();
|
verify(dataSource).getConnection();
|
||||||
|
verify(connection, times(2)).setAutoCommit(false);
|
||||||
|
verify(connection).createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||||
|
verify(statement).setFetchSize(500);
|
||||||
|
verify(statement).setMaxRows(0);
|
||||||
|
verify(statement).execute("query");
|
||||||
|
verify(statement, times(2)).getResultSet();
|
||||||
|
verify(resultSet1).getMetaData();
|
||||||
|
verify(metaData1).getColumnCount();
|
||||||
|
verify(resultSet1).next();
|
||||||
|
verify(resultSet1).close();
|
||||||
|
verify(resultSet2).getMetaData();
|
||||||
|
verify(metaData2).getColumnCount();
|
||||||
|
verify(resultSet2, times(2)).next();
|
||||||
|
verify(resultSet2).close();
|
||||||
|
verify(statement, times(2)).getMoreResults();
|
||||||
|
verify(statement).getUpdateCount();
|
||||||
|
verify(statement).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRetrieveFromDriverManager() throws Exception {
|
public void testRetrieveFromDriverManager() throws Exception {
|
||||||
DriverManager.registerDriver(driver);
|
DriverManager.registerDriver(driver);
|
||||||
try {
|
try {
|
||||||
EasyMock.expect(
|
when(driver.connect(notNull(),notNull())).thenReturn(connection);
|
||||||
driver.connect((String) EasyMock.notNull(), (Properties) EasyMock
|
|
||||||
.notNull())).andReturn(connection);
|
|
||||||
connection.setAutoCommit(false);
|
|
||||||
connection.setHoldability(1);
|
|
||||||
|
|
||||||
props.put(JdbcDataSource.DRIVER, driver.getClass().getName());
|
props.put(JdbcDataSource.DRIVER, driver.getClass().getName());
|
||||||
props.put(JdbcDataSource.URL, "jdbc:fakedb");
|
props.put(JdbcDataSource.URL, "jdbc:fakedb");
|
||||||
props.put("holdability", "HOLD_CURSORS_OVER_COMMIT");
|
props.put("holdability", "HOLD_CURSORS_OVER_COMMIT");
|
||||||
mockControl.replay();
|
|
||||||
|
|
||||||
Connection conn = jdbcDataSource.createConnectionFactory(context, props)
|
Connection conn = jdbcDataSource.createConnectionFactory(context, props)
|
||||||
.call();
|
.call();
|
||||||
|
|
||||||
mockControl.verify();
|
verify(connection).setAutoCommit(false);
|
||||||
|
verify(connection).setHoldability(1);
|
||||||
|
|
||||||
assertSame("connection", conn, connection);
|
assertSame("connection", conn, connection);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -539,36 +512,40 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
|
||||||
MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
|
MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
|
||||||
|
|
||||||
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
|
||||||
EasyMock.expect(dataSource.getConnection()).andReturn(connection);
|
when(dataSource.getConnection()).thenReturn(connection);
|
||||||
|
|
||||||
jdbcDataSource.init(context, props);
|
jdbcDataSource.init(context, props);
|
||||||
|
|
||||||
connection.setAutoCommit(false);
|
Statement statement = mock(Statement.class);
|
||||||
|
when(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY))
|
||||||
Statement statement = mockControl.createMock(Statement.class);
|
.thenReturn(statement);
|
||||||
EasyMock.expect(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY))
|
when(statement.execute("query")).thenReturn(true);
|
||||||
.andReturn(statement);
|
ResultSet resultSet = mock(ResultSet.class);
|
||||||
statement.setFetchSize(500);
|
when(statement.getResultSet()).thenReturn(resultSet);
|
||||||
statement.setMaxRows(0);
|
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
|
||||||
EasyMock.expect(statement.execute("query")).andReturn(true);
|
when(resultSet.getMetaData()).thenReturn(metaData);
|
||||||
ResultSet resultSet = mockControl.createMock(ResultSet.class);
|
when(metaData.getColumnCount()).thenReturn(0);
|
||||||
EasyMock.expect(statement.getResultSet()).andReturn(resultSet);
|
when(resultSet.next()).thenReturn(false);
|
||||||
ResultSetMetaData metaData = mockControl.createMock(ResultSetMetaData.class);
|
when(statement.getMoreResults()).thenReturn(false);
|
||||||
EasyMock.expect(resultSet.getMetaData()).andReturn(metaData);
|
when(statement.getUpdateCount()).thenReturn(-1);
|
||||||
EasyMock.expect(metaData.getColumnCount()).andReturn(0);
|
|
||||||
EasyMock.expect(resultSet.next()).andReturn(false);
|
|
||||||
resultSet.close();
|
|
||||||
EasyMock.expect(statement.getMoreResults()).andReturn(false);
|
|
||||||
EasyMock.expect(statement.getUpdateCount()).andReturn(-1);
|
|
||||||
statement.close();
|
|
||||||
|
|
||||||
mockControl.replay();
|
|
||||||
|
|
||||||
Iterator<Map<String,Object>> resultSetIterator = jdbcDataSource.getData("query");
|
Iterator<Map<String,Object>> resultSetIterator = jdbcDataSource.getData("query");
|
||||||
resultSetIterator.hasNext();
|
resultSetIterator.hasNext();
|
||||||
resultSetIterator.hasNext();
|
resultSetIterator.hasNext();
|
||||||
|
|
||||||
mockControl.verify();
|
verify(connection).setAutoCommit(false);
|
||||||
|
verify(connection).createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||||
|
verify(statement).setFetchSize(500);
|
||||||
|
verify(statement).setMaxRows(0);
|
||||||
|
verify(statement).execute("query");
|
||||||
|
verify(statement).getResultSet();
|
||||||
|
verify(resultSet).getMetaData();
|
||||||
|
verify(metaData).getColumnCount();
|
||||||
|
verify(resultSet).next();
|
||||||
|
verify(resultSet).close();
|
||||||
|
verify(statement).getMoreResults();
|
||||||
|
verify(statement).getUpdateCount();
|
||||||
|
verify(statement).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -51,10 +51,6 @@
|
||||||
<dependency org="org.slf4j" name="slf4j-log4j12" rev="${/org.slf4j/slf4j-log4j12}" conf="compile"/>
|
<dependency org="org.slf4j" name="slf4j-log4j12" rev="${/org.slf4j/slf4j-log4j12}" conf="compile"/>
|
||||||
<dependency org="org.slf4j" name="jcl-over-slf4j" rev="${/org.slf4j/jcl-over-slf4j}" conf="compile"/>
|
<dependency org="org.slf4j" name="jcl-over-slf4j" rev="${/org.slf4j/jcl-over-slf4j}" conf="compile"/>
|
||||||
|
|
||||||
<!-- TODO: Nuke those 2 deps, please!!!! -->
|
|
||||||
<dependency org="org.easymock" name="easymock" rev="${/org.easymock/easymock}" conf="test"/>
|
|
||||||
<dependency org="cglib" name="cglib-nodep" rev="${/cglib/cglib-nodep}" conf="test"/>
|
|
||||||
|
|
||||||
<dependency org="org.mockito" name="mockito-core" rev="${/org.mockito/mockito-core}" conf="test"/>
|
<dependency org="org.mockito" name="mockito-core" rev="${/org.mockito/mockito-core}" conf="test"/>
|
||||||
<dependency org="net.bytebuddy" name="byte-buddy" rev="${/net.bytebuddy/byte-buddy}" conf="test"/>
|
<dependency org="net.bytebuddy" name="byte-buddy" rev="${/net.bytebuddy/byte-buddy}" conf="test"/>
|
||||||
<dependency org="org.objenesis" name="objenesis" rev="${/org.objenesis/objenesis}" conf="test"/>
|
<dependency org="org.objenesis" name="objenesis" rev="${/org.objenesis/objenesis}" conf="test"/>
|
||||||
|
|
|
@ -21,28 +21,17 @@ import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.lucene.util.Constants;
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.common.cloud.ClusterState;
|
import org.apache.solr.common.cloud.ClusterState;
|
||||||
import org.apache.solr.common.cloud.DocCollection;
|
import org.apache.solr.common.cloud.DocCollection;
|
||||||
import org.apache.solr.common.cloud.DocRouter;
|
import org.apache.solr.common.cloud.DocRouter;
|
||||||
import org.apache.solr.common.cloud.Slice;
|
import org.apache.solr.common.cloud.Slice;
|
||||||
import org.apache.solr.common.cloud.Replica;
|
import org.apache.solr.common.cloud.Replica;
|
||||||
import org.apache.solr.common.cloud.ZkStateReader;
|
|
||||||
import org.apache.solr.common.util.Utils;
|
import org.apache.solr.common.util.Utils;
|
||||||
import org.easymock.EasyMock;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.createMock;
|
|
||||||
|
|
||||||
public class ClusterStateTest extends SolrTestCaseJ4 {
|
public class ClusterStateTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void beforeClass() throws Exception {
|
|
||||||
assumeFalse("SOLR-9893: EasyMock does not work with Java 9", Constants.JRE_IS_MINIMUM_JAVA9);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStoreAndRead() throws Exception {
|
public void testStoreAndRead() throws Exception {
|
||||||
Map<String,DocCollection> collectionStates = new HashMap<>();
|
Map<String,DocCollection> collectionStates = new HashMap<>();
|
||||||
|
@ -64,7 +53,6 @@ public class ClusterStateTest extends SolrTestCaseJ4 {
|
||||||
slices.put("shard2", slice2);
|
slices.put("shard2", slice2);
|
||||||
collectionStates.put("collection1", new DocCollection("collection1", slices, null, DocRouter.DEFAULT));
|
collectionStates.put("collection1", new DocCollection("collection1", slices, null, DocRouter.DEFAULT));
|
||||||
collectionStates.put("collection2", new DocCollection("collection2", slices, null, DocRouter.DEFAULT));
|
collectionStates.put("collection2", new DocCollection("collection2", slices, null, DocRouter.DEFAULT));
|
||||||
ZkStateReader zkStateReaderMock = getMockZkStateReader(collectionStates.keySet());
|
|
||||||
|
|
||||||
ClusterState clusterState = new ClusterState(-1,liveNodes, collectionStates);
|
ClusterState clusterState = new ClusterState(-1,liveNodes, collectionStates);
|
||||||
byte[] bytes = Utils.toJSON(clusterState);
|
byte[] bytes = Utils.toJSON(clusterState);
|
||||||
|
@ -90,11 +78,4 @@ public class ClusterStateTest extends SolrTestCaseJ4 {
|
||||||
assertEquals("Should not have collections", 0, loadedClusterState.getCollectionsMap().size());
|
assertEquals("Should not have collections", 0, loadedClusterState.getCollectionsMap().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ZkStateReader getMockZkStateReader(final Set<String> collections) {
|
|
||||||
ZkStateReader mock = createMock(ZkStateReader.class);
|
|
||||||
EasyMock.reset(mock);
|
|
||||||
EasyMock.replay(mock);
|
|
||||||
|
|
||||||
return mock;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,12 +21,9 @@ import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
import org.apache.lucene.util.Constants;
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.client.solrj.SolrResponse;
|
import org.apache.solr.client.solrj.SolrResponse;
|
||||||
import org.apache.solr.client.solrj.response.QueryResponse;
|
|
||||||
import org.apache.solr.cloud.Overseer.LeaderStatus;
|
import org.apache.solr.cloud.Overseer.LeaderStatus;
|
||||||
import org.apache.solr.cloud.OverseerTaskQueue.QueueEvent;
|
import org.apache.solr.cloud.OverseerTaskQueue.QueueEvent;
|
||||||
import org.apache.solr.common.cloud.ClusterState;
|
import org.apache.solr.common.cloud.ClusterState;
|
||||||
|
@ -42,21 +39,17 @@ import org.apache.solr.common.util.Utils;
|
||||||
import org.apache.solr.handler.component.ShardHandler;
|
import org.apache.solr.handler.component.ShardHandler;
|
||||||
import org.apache.solr.handler.component.ShardHandlerFactory;
|
import org.apache.solr.handler.component.ShardHandlerFactory;
|
||||||
import org.apache.solr.handler.component.ShardRequest;
|
import org.apache.solr.handler.component.ShardRequest;
|
||||||
import org.apache.solr.handler.component.ShardResponse;
|
|
||||||
import org.apache.solr.util.TimeOut;
|
import org.apache.solr.util.TimeOut;
|
||||||
import org.apache.zookeeper.CreateMode;
|
|
||||||
import org.apache.zookeeper.Watcher;
|
|
||||||
import org.easymock.Capture;
|
|
||||||
import org.easymock.EasyMock;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class OverseerCollectionConfigSetProcessorTest extends SolrTestCaseJ4 {
|
public class OverseerCollectionConfigSetProcessorTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
|
@ -107,16 +100,15 @@ public class OverseerCollectionConfigSetProcessorTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpOnce() throws Exception {
|
public static void setUpOnce() throws Exception {
|
||||||
assumeFalse("SOLR-9893: EasyMock does not work with Java 9", Constants.JRE_IS_MINIMUM_JAVA9);
|
workQueueMock = mock(OverseerTaskQueue.class);
|
||||||
workQueueMock = createMock(OverseerTaskQueue.class);
|
runningMapMock = mock(DistributedMap.class);
|
||||||
runningMapMock = createMock(DistributedMap.class);
|
completedMapMock = mock(DistributedMap.class);
|
||||||
completedMapMock = createMock(DistributedMap.class);
|
failureMapMock = mock(DistributedMap.class);
|
||||||
failureMapMock = createMock(DistributedMap.class);
|
shardHandlerFactoryMock = mock(ShardHandlerFactory.class);
|
||||||
shardHandlerFactoryMock = createMock(ShardHandlerFactory.class);
|
shardHandlerMock = mock(ShardHandler.class);
|
||||||
shardHandlerMock = createMock(ShardHandler.class);
|
zkStateReaderMock = mock(ZkStateReader.class);
|
||||||
zkStateReaderMock = createMock(ZkStateReader.class);
|
clusterStateMock = mock(ClusterState.class);
|
||||||
clusterStateMock = createMock(ClusterState.class);
|
solrZkClientMock = mock(SolrZkClient.class);
|
||||||
solrZkClientMock = createMock(SolrZkClient.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
|
@ -157,14 +149,8 @@ public class OverseerCollectionConfigSetProcessorTest extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Set<String> commonMocks(int liveNodesCount) throws Exception {
|
protected Set<String> commonMocks(int liveNodesCount) throws Exception {
|
||||||
shardHandlerFactoryMock.getShardHandler();
|
when(shardHandlerFactoryMock.getShardHandler()).thenReturn(shardHandlerMock);
|
||||||
expectLastCall().andAnswer(() -> {
|
when(workQueueMock.peekTopN(anyInt(), any(), anyLong())).thenAnswer(invocation -> {
|
||||||
log.info("SHARDHANDLER");
|
|
||||||
return shardHandlerMock;
|
|
||||||
}).anyTimes();
|
|
||||||
|
|
||||||
workQueueMock.peekTopN(EasyMock.anyInt(), anyObject(Predicate.class), EasyMock.anyLong());
|
|
||||||
expectLastCall().andAnswer(() -> {
|
|
||||||
Object result;
|
Object result;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while ((result = queue.peek()) == null) {
|
while ((result = queue.peek()) == null) {
|
||||||
|
@ -174,112 +160,68 @@ public class OverseerCollectionConfigSetProcessorTest extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
|
|
||||||
return Arrays.asList(result);
|
return Arrays.asList(result);
|
||||||
}).anyTimes();
|
});
|
||||||
|
|
||||||
workQueueMock.getTailId();
|
when(workQueueMock.getTailId()).thenAnswer(invocation -> {
|
||||||
expectLastCall().andAnswer(() -> {
|
|
||||||
Object result = null;
|
Object result = null;
|
||||||
Iterator iter = queue.iterator();
|
Iterator iter = queue.iterator();
|
||||||
while(iter.hasNext()) {
|
while(iter.hasNext()) {
|
||||||
result = iter.next();
|
result = iter.next();
|
||||||
}
|
}
|
||||||
return result==null ? null : ((QueueEvent)result).getId();
|
return result==null ? null : ((QueueEvent)result).getId();
|
||||||
}).anyTimes();
|
});
|
||||||
|
|
||||||
workQueueMock.peek(true);
|
when(workQueueMock.peek(true)).thenAnswer(invocation -> {
|
||||||
expectLastCall().andAnswer(() -> {
|
|
||||||
Object result;
|
Object result;
|
||||||
while ((result = queue.peek()) == null) {
|
while ((result = queue.peek()) == null) {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}).anyTimes();
|
});
|
||||||
|
|
||||||
workQueueMock.remove(anyObject(QueueEvent.class));
|
doAnswer(invocation -> {
|
||||||
expectLastCall().andAnswer(() -> {
|
queue.remove(invocation.getArgument(0));
|
||||||
queue.remove(getCurrentArguments()[0]);
|
|
||||||
return null;
|
return null;
|
||||||
}).anyTimes();
|
}).when(workQueueMock).remove(any());
|
||||||
|
|
||||||
workQueueMock.poll();
|
when(workQueueMock.poll()).thenAnswer(invocation -> {
|
||||||
expectLastCall().andAnswer(() -> queue.poll()).anyTimes();
|
queue.poll();
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
zkStateReaderMock.getZkClient();
|
when(zkStateReaderMock.getZkClient()).thenReturn(solrZkClientMock);
|
||||||
expectLastCall().andAnswer(() -> solrZkClientMock).anyTimes();
|
when(zkStateReaderMock.getClusterState()).thenReturn(clusterStateMock);
|
||||||
|
|
||||||
zkStateReaderMock.getClusterState();
|
when(clusterStateMock.getCollections()).thenReturn(collectionsSet);
|
||||||
expectLastCall().andAnswer(() -> clusterStateMock).anyTimes();
|
|
||||||
|
|
||||||
zkStateReaderMock.updateClusterState();
|
|
||||||
|
|
||||||
clusterStateMock.getCollections();
|
|
||||||
expectLastCall().andAnswer(() -> collectionsSet).anyTimes();
|
|
||||||
final Set<String> liveNodes = new HashSet<>();
|
final Set<String> liveNodes = new HashSet<>();
|
||||||
for (int i = 0; i < liveNodesCount; i++) {
|
for (int i = 0; i < liveNodesCount; i++) {
|
||||||
final String address = "localhost:" + (8963 + i) + "_solr";
|
final String address = "localhost:" + (8963 + i) + "_solr";
|
||||||
liveNodes.add(address);
|
liveNodes.add(address);
|
||||||
|
|
||||||
zkStateReaderMock.getBaseUrlForNodeName(address);
|
when(zkStateReaderMock.getBaseUrlForNodeName(address)).thenAnswer(invocation -> address.replaceAll("_", "/"));
|
||||||
expectLastCall().andAnswer(() -> {
|
|
||||||
// This works as long as this test does not use a
|
|
||||||
// webapp context with an underscore in it
|
|
||||||
return address.replaceAll("_", "/");
|
|
||||||
}).anyTimes();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
zkStateReaderMock.getClusterProperty("legacyCloud", "true");
|
when(zkStateReaderMock.getClusterProperty("legacyCloud", "true")).thenReturn("true");
|
||||||
expectLastCall().andAnswer(() -> "true");
|
|
||||||
|
|
||||||
solrZkClientMock.getZkClientTimeout();
|
when(solrZkClientMock.getZkClientTimeout()).thenReturn(30000);
|
||||||
expectLastCall().andAnswer(() -> 30000).anyTimes();
|
|
||||||
|
|
||||||
clusterStateMock.hasCollection(anyObject(String.class));
|
when(clusterStateMock.hasCollection(anyString())).thenAnswer(invocation -> {
|
||||||
expectLastCall().andAnswer(() -> {
|
String key = invocation.getArgument(0);
|
||||||
String key = (String) getCurrentArguments()[0];
|
|
||||||
return collectionsSet.contains(key);
|
return collectionsSet.contains(key);
|
||||||
}).anyTimes();
|
});
|
||||||
|
|
||||||
|
when(clusterStateMock.getLiveNodes()).thenReturn(liveNodes);
|
||||||
clusterStateMock.getLiveNodes();
|
when(solrZkClientMock.create(any(), any(), any(), anyBoolean())).thenAnswer(invocation -> {
|
||||||
expectLastCall().andAnswer(() -> liveNodes).anyTimes();
|
String key = invocation.getArgument(0);
|
||||||
solrZkClientMock.create(anyObject(String.class), anyObject(byte[].class), anyObject(CreateMode.class), anyBoolean());
|
|
||||||
expectLastCall().andAnswer(() -> {
|
|
||||||
String key = (String) getCurrentArguments()[0];
|
|
||||||
zkMap.put(key, null);
|
zkMap.put(key, null);
|
||||||
handleCreateCollMessage((byte[]) getCurrentArguments()[1]);
|
handleCreateCollMessage(invocation.getArgument(1));
|
||||||
return key;
|
return key;
|
||||||
}).anyTimes();
|
});
|
||||||
|
|
||||||
solrZkClientMock.makePath(anyObject(String.class), anyObject(byte[].class), anyBoolean());
|
when(solrZkClientMock.exists(any(String.class), anyBoolean())).thenAnswer(invocation -> {
|
||||||
expectLastCall().andAnswer(() -> {
|
String key = invocation.getArgument(0);
|
||||||
String key = (String) getCurrentArguments()[0];
|
|
||||||
return key;
|
|
||||||
}).anyTimes();
|
|
||||||
|
|
||||||
solrZkClientMock.makePath(anyObject(String.class), anyObject(byte[].class), anyObject(CreateMode.class), anyBoolean());
|
|
||||||
expectLastCall().andAnswer(() -> {
|
|
||||||
String key = (String) getCurrentArguments()[0];
|
|
||||||
return key;
|
|
||||||
}).anyTimes();
|
|
||||||
|
|
||||||
solrZkClientMock.makePath(anyObject(String.class), anyObject(byte[].class), anyObject(CreateMode.class), anyObject(Watcher.class), anyBoolean());
|
|
||||||
expectLastCall().andAnswer(() -> {
|
|
||||||
String key = (String) getCurrentArguments()[0];
|
|
||||||
return key;
|
|
||||||
}).anyTimes();
|
|
||||||
|
|
||||||
solrZkClientMock.makePath(anyObject(String.class), anyObject(byte[].class), anyObject(CreateMode.class), anyObject(Watcher.class), anyBoolean(), anyBoolean(), anyInt());
|
|
||||||
expectLastCall().andAnswer(() -> {
|
|
||||||
String key = (String) getCurrentArguments()[0];
|
|
||||||
return key;
|
|
||||||
}).anyTimes();
|
|
||||||
|
|
||||||
solrZkClientMock.exists(anyObject(String.class),anyBoolean());
|
|
||||||
expectLastCall().andAnswer(() -> {
|
|
||||||
String key = (String) getCurrentArguments()[0];
|
|
||||||
return zkMap.containsKey(key);
|
return zkMap.containsKey(key);
|
||||||
}).anyTimes();
|
});
|
||||||
|
|
||||||
zkMap.put("/configs/myconfig", null);
|
zkMap.put("/configs/myconfig", null);
|
||||||
|
|
||||||
|
@ -307,31 +249,6 @@ public class OverseerCollectionConfigSetProcessorTest extends SolrTestCaseJ4 {
|
||||||
thread.join();
|
thread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SubmitCapture {
|
|
||||||
public Capture<ShardRequest> shardRequestCapture = new Capture<>();
|
|
||||||
public Capture<String> nodeUrlsWithoutProtocolPartCapture = new Capture<>();
|
|
||||||
public Capture<ModifiableSolrParams> params = new Capture<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<SubmitCapture> mockShardHandlerForCreateJob(
|
|
||||||
Integer numberOfSlices, Integer numberOfReplica) {
|
|
||||||
List<SubmitCapture> submitCaptures = new ArrayList<>();
|
|
||||||
for (int i = 0; i < (numberOfSlices * numberOfReplica); i++) {
|
|
||||||
SubmitCapture submitCapture = new SubmitCapture();
|
|
||||||
shardHandlerMock.submit(capture(submitCapture.shardRequestCapture),
|
|
||||||
capture(submitCapture.nodeUrlsWithoutProtocolPartCapture),
|
|
||||||
capture(submitCapture.params));
|
|
||||||
expectLastCall();
|
|
||||||
submitCaptures.add(submitCapture);
|
|
||||||
ShardResponse shardResponseWithoutException = new ShardResponse();
|
|
||||||
shardResponseWithoutException.setSolrResponse(new QueryResponse());
|
|
||||||
expect(shardHandlerMock.takeCompletedOrError()).andReturn(
|
|
||||||
shardResponseWithoutException);
|
|
||||||
}
|
|
||||||
expect(shardHandlerMock.takeCompletedOrError()).andReturn(null);
|
|
||||||
return submitCaptures;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void issueCreateJob(Integer numberOfSlices,
|
protected void issueCreateJob(Integer numberOfSlices,
|
||||||
Integer replicationFactor, Integer maxShardsPerNode, List<String> createNodeList, boolean sendCreateNodeList, boolean createNodeSetShuffle) {
|
Integer replicationFactor, Integer maxShardsPerNode, List<String> createNodeList, boolean sendCreateNodeList, boolean createNodeSetShuffle) {
|
||||||
Map<String,Object> propMap = Utils.makeMap(
|
Map<String,Object> propMap = Utils.makeMap(
|
||||||
|
@ -360,7 +277,7 @@ public class OverseerCollectionConfigSetProcessorTest extends SolrTestCaseJ4 {
|
||||||
queue.add(qe);
|
queue.add(qe);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void verifySubmitCaptures(List<SubmitCapture> submitCaptures,
|
protected void verifySubmitCaptures(
|
||||||
Integer numberOfSlices, Integer numberOfReplica, Collection<String> createNodes, boolean dontShuffleCreateNodeSet) {
|
Integer numberOfSlices, Integer numberOfReplica, Collection<String> createNodes, boolean dontShuffleCreateNodeSet) {
|
||||||
List<String> coreNames = new ArrayList<>();
|
List<String> coreNames = new ArrayList<>();
|
||||||
Map<String,Map<String,Integer>> sliceToNodeUrlsWithoutProtocolPartToNumberOfShardsRunningMapMap = new HashMap<>();
|
Map<String,Map<String,Integer>> sliceToNodeUrlsWithoutProtocolPartToNumberOfShardsRunningMapMap = new HashMap<>();
|
||||||
|
@ -374,8 +291,16 @@ public class OverseerCollectionConfigSetProcessorTest extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
final Map<String,String> coreName_TO_nodeUrlWithoutProtocolPartForLiveNodes_map = new HashMap<>();
|
final Map<String,String> coreName_TO_nodeUrlWithoutProtocolPartForLiveNodes_map = new HashMap<>();
|
||||||
|
|
||||||
for (SubmitCapture submitCapture : submitCaptures) {
|
ArgumentCaptor<ShardRequest> shardRequestCaptor = ArgumentCaptor.forClass(ShardRequest.class);
|
||||||
ShardRequest shardRequest = submitCapture.shardRequestCapture.getValue();
|
ArgumentCaptor<String> nodeUrlsWithoutProtocolPartCaptor = ArgumentCaptor.forClass(String.class);
|
||||||
|
ArgumentCaptor<ModifiableSolrParams> paramsCaptor = ArgumentCaptor.forClass(ModifiableSolrParams.class);
|
||||||
|
verify(shardHandlerMock, times(numberOfReplica * numberOfSlices))
|
||||||
|
.submit(shardRequestCaptor.capture(), nodeUrlsWithoutProtocolPartCaptor.capture(), paramsCaptor.capture());
|
||||||
|
log.info("Datcmzz " + shardRequestCaptor.getAllValues().size());
|
||||||
|
for (int i = 0; i < shardRequestCaptor.getAllValues().size(); i++) {
|
||||||
|
ShardRequest shardRequest = shardRequestCaptor.getAllValues().get(i);
|
||||||
|
String nodeUrlsWithoutProtocolPartCapture = nodeUrlsWithoutProtocolPartCaptor.getAllValues().get(i);
|
||||||
|
ModifiableSolrParams params = paramsCaptor.getAllValues().get(i);
|
||||||
assertEquals(CoreAdminAction.CREATE.toString(),
|
assertEquals(CoreAdminAction.CREATE.toString(),
|
||||||
shardRequest.params.get(CoreAdminParams.ACTION));
|
shardRequest.params.get(CoreAdminParams.ACTION));
|
||||||
// assertEquals(shardRequest.params, submitCapture.params);
|
// assertEquals(shardRequest.params, submitCapture.params);
|
||||||
|
@ -392,7 +317,7 @@ public class OverseerCollectionConfigSetProcessorTest extends SolrTestCaseJ4 {
|
||||||
assertEquals(ADMIN_PATH, shardRequest.params.get("qt"));
|
assertEquals(ADMIN_PATH, shardRequest.params.get("qt"));
|
||||||
assertEquals(1, shardRequest.purpose);
|
assertEquals(1, shardRequest.purpose);
|
||||||
assertEquals(1, shardRequest.shards.length);
|
assertEquals(1, shardRequest.shards.length);
|
||||||
assertEquals(submitCapture.nodeUrlsWithoutProtocolPartCapture.getValue(),
|
assertEquals(nodeUrlsWithoutProtocolPartCapture,
|
||||||
shardRequest.shards[0]);
|
shardRequest.shards[0]);
|
||||||
assertTrue("Shard " + coreName + " created on wrong node "
|
assertTrue("Shard " + coreName + " created on wrong node "
|
||||||
+ shardRequest.shards[0],
|
+ shardRequest.shards[0],
|
||||||
|
@ -524,20 +449,6 @@ public class OverseerCollectionConfigSetProcessorTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
if (random().nextBoolean()) Collections.shuffle(createNodeList, OverseerCollectionMessageHandler.RANDOM);
|
if (random().nextBoolean()) Collections.shuffle(createNodeList, OverseerCollectionMessageHandler.RANDOM);
|
||||||
|
|
||||||
List<SubmitCapture> submitCaptures = null;
|
|
||||||
if (collectionExceptedToBeCreated) {
|
|
||||||
submitCaptures = mockShardHandlerForCreateJob(numberOfSlices,
|
|
||||||
replicationFactor);
|
|
||||||
}
|
|
||||||
|
|
||||||
replay(solrZkClientMock);
|
|
||||||
replay(zkStateReaderMock);
|
|
||||||
replay(workQueueMock);
|
|
||||||
replay(clusterStateMock);
|
|
||||||
replay(shardHandlerFactoryMock);
|
|
||||||
replay(shardHandlerMock);
|
|
||||||
|
|
||||||
|
|
||||||
underTest = new OverseerCollectionConfigSetProcessorToBeTested(zkStateReaderMock,
|
underTest = new OverseerCollectionConfigSetProcessorToBeTested(zkStateReaderMock,
|
||||||
"1234", shardHandlerFactoryMock, ADMIN_PATH, workQueueMock, runningMapMock,
|
"1234", shardHandlerFactoryMock, ADMIN_PATH, workQueueMock, runningMapMock,
|
||||||
completedMapMock, failureMapMock);
|
completedMapMock, failureMapMock);
|
||||||
|
@ -556,11 +467,9 @@ public class OverseerCollectionConfigSetProcessorTest extends SolrTestCaseJ4 {
|
||||||
if (collectionExceptedToBeCreated) {
|
if (collectionExceptedToBeCreated) {
|
||||||
assertNotNull(lastProcessMessageResult.getResponse().toString(), lastProcessMessageResult);
|
assertNotNull(lastProcessMessageResult.getResponse().toString(), lastProcessMessageResult);
|
||||||
}
|
}
|
||||||
verify(shardHandlerFactoryMock);
|
|
||||||
verify(shardHandlerMock);
|
|
||||||
|
|
||||||
if (collectionExceptedToBeCreated) {
|
if (collectionExceptedToBeCreated) {
|
||||||
verifySubmitCaptures(submitCaptures, numberOfSlices, replicationFactor,
|
verifySubmitCaptures(numberOfSlices, replicationFactor,
|
||||||
createNodeList, dontShuffleCreateNodeSet);
|
createNodeList, dontShuffleCreateNodeSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,18 +25,11 @@ import java.nio.charset.Charset;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.lucene.util.Constants;
|
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.easymock.EasyMock;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.anyObject;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.easymock.EasyMock.eq;
|
|
||||||
import static org.easymock.EasyMock.expect;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
@ -47,18 +40,12 @@ public class BlobRepositoryMockingTest {
|
||||||
private static final Charset UTF8 = Charset.forName("UTF-8");
|
private static final Charset UTF8 = Charset.forName("UTF-8");
|
||||||
private static final String[][] PARSED = new String[][]{{"foo", "bar", "baz"}, {"bang", "boom", "bash"}};
|
private static final String[][] PARSED = new String[][]{{"foo", "bar", "baz"}, {"bang", "boom", "bash"}};
|
||||||
private static final String BLOBSTR = "foo,bar,baz\nbang,boom,bash";
|
private static final String BLOBSTR = "foo,bar,baz\nbang,boom,bash";
|
||||||
private CoreContainer mockContainer = EasyMock.createMock(CoreContainer.class);
|
private CoreContainer mockContainer = mock(CoreContainer.class);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private ConcurrentHashMap<String, BlobRepository.BlobContent> mapMock = EasyMock.createMock(ConcurrentHashMap.class);
|
private ConcurrentHashMap<String, BlobRepository.BlobContent> mapMock = mock(ConcurrentHashMap.class);
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private BlobRepository.Decoder<Object> decoderMock = EasyMock.createMock(BlobRepository.Decoder.class);;
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private BlobRepository.BlobContent<Object> blobContentMock = EasyMock.createMock(BlobRepository.BlobContent.class);
|
|
||||||
|
|
||||||
private Object[] mocks = new Object[] {
|
private Object[] mocks = new Object[] {
|
||||||
mockContainer,
|
mockContainer,
|
||||||
decoderMock,
|
|
||||||
blobContentMock,
|
|
||||||
mapMock
|
mapMock
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -67,16 +54,11 @@ public class BlobRepositoryMockingTest {
|
||||||
boolean blobFetched = false;
|
boolean blobFetched = false;
|
||||||
String blobKey = "";
|
String blobKey = "";
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void beforeClass() throws Exception {
|
|
||||||
LuceneTestCase.assumeFalse("SOLR-9893: EasyMock does not work with Java 9", Constants.JRE_IS_MINIMUM_JAVA9);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws IllegalAccessException, NoSuchFieldException {
|
public void setUp() throws IllegalAccessException, NoSuchFieldException {
|
||||||
blobFetched = false;
|
blobFetched = false;
|
||||||
blobKey = "";
|
blobKey = "";
|
||||||
EasyMock.reset(mocks);
|
reset(mocks);
|
||||||
repository = new BlobRepository(mockContainer) {
|
repository = new BlobRepository(mockContainer) {
|
||||||
@Override
|
@Override
|
||||||
ByteBuffer fetchBlob(String key) {
|
ByteBuffer fetchBlob(String key) {
|
||||||
|
@ -93,53 +75,49 @@ public class BlobRepositoryMockingTest {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
EasyMock.verify(mocks);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test (expected = SolrException.class)
|
@Test (expected = SolrException.class)
|
||||||
public void testCloudOnly() {
|
public void testCloudOnly() {
|
||||||
expect(mockContainer.isZooKeeperAware()).andReturn(false);
|
when(mockContainer.isZooKeeperAware()).thenReturn(false);
|
||||||
EasyMock.replay(mocks);
|
try {
|
||||||
BlobRepository.BlobContentRef ref = repository.getBlobIncRef("foo!");
|
BlobRepository.BlobContentRef ref = repository.getBlobIncRef("foo!");
|
||||||
|
} catch (SolrException e) {
|
||||||
|
verify(mockContainer).isZooKeeperAware();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testGetBlobIncrRefString() {
|
public void testGetBlobIncrRefString() {
|
||||||
expect(mockContainer.isZooKeeperAware()).andReturn(true);
|
when(mockContainer.isZooKeeperAware()).thenReturn(true);
|
||||||
expect(mapMock.get("foo!")).andReturn(null);
|
|
||||||
expect(mapMock.put(eq("foo!"), anyObject(BlobRepository.BlobContent.class))).andReturn(null);
|
|
||||||
EasyMock.replay(mocks);
|
|
||||||
BlobRepository.BlobContentRef ref = repository.getBlobIncRef("foo!");
|
BlobRepository.BlobContentRef ref = repository.getBlobIncRef("foo!");
|
||||||
assertTrue("foo!".equals(blobKey));
|
assertTrue("foo!".equals(blobKey));
|
||||||
assertTrue(blobFetched);
|
assertTrue(blobFetched);
|
||||||
assertNotNull(ref.blob);
|
assertNotNull(ref.blob);
|
||||||
assertEquals(blobData, ref.blob.get());
|
assertEquals(blobData, ref.blob.get());
|
||||||
|
verify(mockContainer).isZooKeeperAware();
|
||||||
|
verify(mapMock).get("foo!");
|
||||||
|
verify(mapMock).put(eq("foo!"), any(BlobRepository.BlobContent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testCachedAlready() {
|
public void testCachedAlready() {
|
||||||
expect(mockContainer.isZooKeeperAware()).andReturn(true);
|
when(mockContainer.isZooKeeperAware()).thenReturn(true);
|
||||||
expect(mapMock.get("foo!")).andReturn(new BlobRepository.BlobContent<BlobRepository>("foo!", blobData));
|
when(mapMock.get("foo!")).thenReturn(new BlobRepository.BlobContent<BlobRepository>("foo!", blobData));
|
||||||
EasyMock.replay(mocks);
|
|
||||||
BlobRepository.BlobContentRef ref = repository.getBlobIncRef("foo!");
|
BlobRepository.BlobContentRef ref = repository.getBlobIncRef("foo!");
|
||||||
assertEquals("",blobKey);
|
assertEquals("",blobKey);
|
||||||
assertFalse(blobFetched);
|
assertFalse(blobFetched);
|
||||||
assertNotNull(ref.blob);
|
assertNotNull(ref.blob);
|
||||||
assertEquals(blobData, ref.blob.get());
|
assertEquals(blobData, ref.blob.get());
|
||||||
|
verify(mockContainer).isZooKeeperAware();
|
||||||
|
verify(mapMock).get("foo!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testGetBlobIncrRefStringDecoder() {
|
public void testGetBlobIncrRefStringDecoder() {
|
||||||
expect(mockContainer.isZooKeeperAware()).andReturn(true);
|
when(mockContainer.isZooKeeperAware()).thenReturn(true);
|
||||||
expect(mapMock.get("foo!mocked")).andReturn(null);
|
|
||||||
expect(mapMock.put(eq("foo!mocked"), anyObject(BlobRepository.BlobContent.class))).andReturn(null);
|
|
||||||
|
|
||||||
EasyMock.replay(mocks);
|
|
||||||
BlobRepository.BlobContentRef ref = repository.getBlobIncRef("foo!", new BlobRepository.Decoder<Object>() {
|
BlobRepository.BlobContentRef ref = repository.getBlobIncRef("foo!", new BlobRepository.Decoder<Object>() {
|
||||||
@Override
|
@Override
|
||||||
public Object decode(InputStream inputStream) {
|
public Object decode(InputStream inputStream) {
|
||||||
|
@ -163,6 +141,9 @@ public class BlobRepositoryMockingTest {
|
||||||
assertTrue(blobFetched);
|
assertTrue(blobFetched);
|
||||||
assertNotNull(ref.blob);
|
assertNotNull(ref.blob);
|
||||||
assertEquals(PARSED, ref.blob.get());
|
assertEquals(PARSED, ref.blob.get());
|
||||||
|
verify(mockContainer).isZooKeeperAware();
|
||||||
|
verify(mapMock).get("foo!mocked");
|
||||||
|
verify(mapMock).put(eq("foo!mocked"), any(BlobRepository.BlobContent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.lucene.util.Constants;
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.cloud.CloudDescriptor;
|
import org.apache.solr.cloud.CloudDescriptor;
|
||||||
import org.apache.solr.cloud.ZkController;
|
import org.apache.solr.cloud.ZkController;
|
||||||
|
@ -36,24 +35,15 @@ import org.apache.solr.common.cloud.Replica;
|
||||||
import org.apache.solr.common.util.Utils;
|
import org.apache.solr.common.util.Utils;
|
||||||
import org.apache.solr.core.CoreSorter.CountsForEachShard;
|
import org.apache.solr.core.CoreSorter.CountsForEachShard;
|
||||||
import org.apache.solr.util.MockCoreContainer;
|
import org.apache.solr.util.MockCoreContainer;
|
||||||
import org.junit.BeforeClass;
|
|
||||||
|
|
||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
import static org.apache.solr.core.CoreSorter.getShardName;
|
import static org.apache.solr.core.CoreSorter.getShardName;
|
||||||
import static org.easymock.EasyMock.createMock;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.easymock.EasyMock.expect;
|
|
||||||
import static org.easymock.EasyMock.replay;
|
|
||||||
import static org.easymock.EasyMock.reset;
|
|
||||||
|
|
||||||
public class CoreSorterTest extends SolrTestCaseJ4 {
|
public class CoreSorterTest extends SolrTestCaseJ4 {
|
||||||
Map<String, Boolean> nodes = new LinkedHashMap<>();
|
Map<String, Boolean> nodes = new LinkedHashMap<>();
|
||||||
Set<String> liveNodes = new HashSet<>();
|
Set<String> liveNodes = new HashSet<>();
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void beforeClass() throws Exception {
|
|
||||||
assumeFalse("SOLR-9893: EasyMock does not work with Java 9", Constants.JRE_IS_MINIMUM_JAVA9);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testComparator() {
|
public void testComparator() {
|
||||||
List<CountsForEachShard> l = new ArrayList<>();
|
List<CountsForEachShard> l = new ArrayList<>();
|
||||||
// DOWN LIVE MY
|
// DOWN LIVE MY
|
||||||
|
@ -111,15 +101,13 @@ public class CoreSorterTest extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
|
|
||||||
private CoreContainer getMockContainer() {
|
private CoreContainer getMockContainer() {
|
||||||
CoreContainer mockCC = createMock(CoreContainer.class);
|
CoreContainer mockCC = mock(CoreContainer.class);
|
||||||
ZkController mockZKC = createMock(ZkController.class);
|
ZkController mockZKC = mock(ZkController.class);
|
||||||
ClusterState mockClusterState = createMock(ClusterState.class);
|
ClusterState mockClusterState = mock(ClusterState.class);
|
||||||
reset(mockCC, mockZKC, mockClusterState);
|
when(mockCC.isZooKeeperAware()).thenReturn(true);
|
||||||
expect(mockCC.isZooKeeperAware()).andReturn(Boolean.TRUE).anyTimes();
|
when(mockCC.getZkController()).thenReturn(mockZKC);
|
||||||
expect(mockCC.getZkController()).andReturn(mockZKC).anyTimes();
|
when(mockClusterState.getLiveNodes()).thenReturn(liveNodes);
|
||||||
expect(mockClusterState.getLiveNodes()).andReturn(liveNodes).anyTimes();
|
when(mockZKC.getClusterState()).thenReturn(mockClusterState);
|
||||||
expect(mockZKC.getClusterState()).andReturn(mockClusterState).anyTimes();
|
|
||||||
replay(mockCC, mockZKC, mockClusterState);
|
|
||||||
return mockCC;
|
return mockCC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,27 +24,19 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.apache.lucene.util.Constants;
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.client.solrj.SolrRequest;
|
import org.apache.solr.client.solrj.SolrRequest;
|
||||||
import org.apache.solr.core.CoreContainer;
|
import org.apache.solr.core.CoreContainer;
|
||||||
import org.apache.solr.api.Api;
|
import org.apache.solr.api.Api;
|
||||||
import org.apache.solr.api.ApiBag;
|
import org.apache.solr.api.ApiBag;
|
||||||
import org.easymock.EasyMock;
|
import org.apache.solr.core.PluginBag;
|
||||||
import org.junit.BeforeClass;
|
import org.apache.solr.request.SolrRequestHandler;
|
||||||
|
|
||||||
import static org.apache.solr.common.util.Utils.fromJSONString;
|
import static org.apache.solr.common.util.Utils.fromJSONString;
|
||||||
import static org.easymock.EasyMock.anyBoolean;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.easymock.EasyMock.anyObject;
|
|
||||||
import static org.easymock.EasyMock.getCurrentArguments;
|
|
||||||
|
|
||||||
public class TestCoreAdminApis extends SolrTestCaseJ4 {
|
public class TestCoreAdminApis extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void beforeClass() throws Exception {
|
|
||||||
assumeFalse("SOLR-9893: EasyMock does not work with Java 9", Constants.JRE_IS_MINIMUM_JAVA9);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testCalls() throws Exception {
|
public void testCalls() throws Exception {
|
||||||
Map<String, Object[]> calls = new HashMap<>();
|
Map<String, Object[]> calls = new HashMap<>();
|
||||||
CoreContainer mockCC = getCoreContainerMock(calls, new HashMap<>());
|
CoreContainer mockCC = getCoreContainerMock(calls, new HashMap<>());
|
||||||
|
@ -80,41 +72,33 @@ public class TestCoreAdminApis extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CoreContainer getCoreContainerMock(final Map<String, Object[]> in,Map<String,Object> out ) {
|
public static CoreContainer getCoreContainerMock(final Map<String, Object[]> in,Map<String,Object> out ) {
|
||||||
CoreContainer mockCC = EasyMock.createMock(CoreContainer.class);
|
CoreContainer mockCC = mock(CoreContainer.class);
|
||||||
EasyMock.reset(mockCC);
|
when(mockCC.create(any(String.class), any(Path.class) , any(Map.class), anyBoolean())).thenAnswer(invocationOnMock -> {
|
||||||
mockCC.create(anyObject(String.class), anyObject(Path.class) , anyObject(Map.class), anyBoolean());
|
in.put("create", invocationOnMock.getArguments());
|
||||||
EasyMock.expectLastCall().andAnswer(() -> {
|
|
||||||
in.put("create", getCurrentArguments());
|
|
||||||
return null;
|
return null;
|
||||||
}).anyTimes();
|
});
|
||||||
mockCC.swap(anyObject(String.class), anyObject(String.class));
|
|
||||||
EasyMock.expectLastCall().andAnswer(() -> {
|
|
||||||
in.put("swap", getCurrentArguments());
|
|
||||||
return null;
|
|
||||||
}).anyTimes();
|
|
||||||
|
|
||||||
mockCC.rename(anyObject(String.class), anyObject(String.class));
|
doAnswer(invocationOnMock -> {
|
||||||
EasyMock.expectLastCall().andAnswer(() -> {
|
in.put("swap", invocationOnMock.getArguments());
|
||||||
in.put("rename", getCurrentArguments());
|
|
||||||
return null;
|
return null;
|
||||||
}).anyTimes();
|
}).when(mockCC).swap(any(String.class), any(String.class));
|
||||||
|
|
||||||
mockCC.unload(anyObject(String.class), anyBoolean(),
|
doAnswer(invocationOnMock -> {
|
||||||
|
in.put("rename", invocationOnMock.getArguments());
|
||||||
|
return null;
|
||||||
|
}).when(mockCC).rename(any(String.class), any(String.class));
|
||||||
|
|
||||||
|
|
||||||
|
doAnswer(invocationOnMock -> {
|
||||||
|
in.put("unload", invocationOnMock.getArguments());
|
||||||
|
return null;
|
||||||
|
}).when(mockCC).unload(any(String.class), anyBoolean(),
|
||||||
anyBoolean(), anyBoolean());
|
anyBoolean(), anyBoolean());
|
||||||
EasyMock.expectLastCall().andAnswer(() -> {
|
|
||||||
in.put("unload", getCurrentArguments());
|
|
||||||
return null;
|
|
||||||
}).anyTimes();
|
|
||||||
|
|
||||||
mockCC.getCoreRootDirectory();
|
when(mockCC.getCoreRootDirectory()).thenReturn(Paths.get("coreroot"));
|
||||||
EasyMock.expectLastCall().andAnswer(() -> Paths.get("coreroot")).anyTimes();
|
when(mockCC.getContainerProperties()).thenReturn(new Properties());
|
||||||
mockCC.getContainerProperties();
|
|
||||||
EasyMock.expectLastCall().andAnswer(() -> new Properties()).anyTimes();
|
|
||||||
|
|
||||||
mockCC.getRequestHandlers();
|
when(mockCC.getRequestHandlers()).thenReturn((PluginBag<SolrRequestHandler>) out.get("getRequestHandlers"));
|
||||||
EasyMock.expectLastCall().andAnswer(() -> out.get("getRequestHandlers")).anyTimes();
|
|
||||||
|
|
||||||
EasyMock.replay(mockCC);
|
|
||||||
return mockCC;
|
return mockCC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||||
import org.apache.http.Header;
|
import org.apache.http.Header;
|
||||||
import org.apache.http.auth.BasicUserPrincipal;
|
import org.apache.http.auth.BasicUserPrincipal;
|
||||||
import org.apache.http.message.BasicHttpRequest;
|
import org.apache.http.message.BasicHttpRequest;
|
||||||
import org.apache.lucene.util.Constants;
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.common.params.ModifiableSolrParams;
|
import org.apache.solr.common.params.ModifiableSolrParams;
|
||||||
import org.apache.solr.core.CoreContainer;
|
import org.apache.solr.core.CoreContainer;
|
||||||
|
@ -36,10 +35,7 @@ import org.apache.solr.request.LocalSolrQueryRequest;
|
||||||
import org.apache.solr.request.SolrRequestInfo;
|
import org.apache.solr.request.SolrRequestInfo;
|
||||||
import org.apache.solr.response.SolrQueryResponse;
|
import org.apache.solr.response.SolrQueryResponse;
|
||||||
import org.apache.solr.util.CryptoKeys;
|
import org.apache.solr.util.CryptoKeys;
|
||||||
import org.easymock.EasyMock;
|
import static org.mockito.Mockito.*;
|
||||||
import org.junit.BeforeClass;
|
|
||||||
|
|
||||||
import static org.easymock.EasyMock.getCurrentArguments;
|
|
||||||
|
|
||||||
public class TestPKIAuthenticationPlugin extends SolrTestCaseJ4 {
|
public class TestPKIAuthenticationPlugin extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
|
@ -73,11 +69,6 @@ public class TestPKIAuthenticationPlugin extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void beforeClass() throws Exception {
|
|
||||||
assumeFalse("SOLR-9893: EasyMock does not work with Java 9", Constants.JRE_IS_MINIMUM_JAVA9);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
AtomicReference<Principal> principal = new AtomicReference<>();
|
AtomicReference<Principal> principal = new AtomicReference<>();
|
||||||
String nodeName = "node_x_233";
|
String nodeName = "node_x_233";
|
||||||
|
@ -157,22 +148,14 @@ public class TestPKIAuthenticationPlugin extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
|
|
||||||
private HttpServletRequest createMockRequest(final AtomicReference<Header> header) {
|
private HttpServletRequest createMockRequest(final AtomicReference<Header> header) {
|
||||||
HttpServletRequest mockReq = EasyMock.createMock(HttpServletRequest.class);
|
HttpServletRequest mockReq = mock(HttpServletRequest.class);
|
||||||
EasyMock.reset(mockReq);
|
when(mockReq.getHeader(any(String.class))).then(invocation -> {
|
||||||
mockReq.getHeader(EasyMock.anyObject(String.class));
|
if (PKIAuthenticationPlugin.HEADER.equals(invocation.getArgument(0))) {
|
||||||
EasyMock.expectLastCall().andAnswer(() -> {
|
|
||||||
if (PKIAuthenticationPlugin.HEADER.equals(getCurrentArguments()[0])) {
|
|
||||||
if (header.get() == null) return null;
|
if (header.get() == null) return null;
|
||||||
return header.get().getValue();
|
return header.get().getValue();
|
||||||
} else return null;
|
} else return null;
|
||||||
}).anyTimes();
|
});
|
||||||
mockReq.getUserPrincipal();
|
when(mockReq.getRequestURI()).thenReturn("/collection1/select");
|
||||||
EasyMock.expectLastCall().andAnswer(() -> null).anyTimes();
|
|
||||||
|
|
||||||
mockReq.getRequestURI();
|
|
||||||
EasyMock.expectLastCall().andAnswer(() -> "/collection1/select").anyTimes();
|
|
||||||
|
|
||||||
EasyMock.replay(mockReq);
|
|
||||||
return mockReq;
|
return mockReq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.servlet;
|
package org.apache.solr.servlet;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.anyObject;
|
|
||||||
import static org.easymock.EasyMock.createMock;
|
|
||||||
import static org.easymock.EasyMock.expect;
|
|
||||||
import static org.easymock.EasyMock.replay;
|
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -42,7 +37,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.lucene.util.Constants;
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.common.params.CommonParams;
|
import org.apache.solr.common.params.CommonParams;
|
||||||
|
@ -55,7 +49,7 @@ import org.apache.solr.servlet.SolrRequestParsers.MultipartRequestParser;
|
||||||
import org.apache.solr.servlet.SolrRequestParsers.FormDataRequestParser;
|
import org.apache.solr.servlet.SolrRequestParsers.FormDataRequestParser;
|
||||||
import org.apache.solr.servlet.SolrRequestParsers.RawRequestParser;
|
import org.apache.solr.servlet.SolrRequestParsers.RawRequestParser;
|
||||||
import org.apache.solr.servlet.SolrRequestParsers.StandardRequestParser;
|
import org.apache.solr.servlet.SolrRequestParsers.StandardRequestParser;
|
||||||
import org.easymock.EasyMock;
|
import static org.mockito.Mockito.*;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -68,8 +62,6 @@ public class SolrRequestParserTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() throws Exception {
|
public static void beforeClass() throws Exception {
|
||||||
assumeFalse("SOLR-9893: EasyMock does not work with Java 9", Constants.JRE_IS_MINIMUM_JAVA9);
|
|
||||||
|
|
||||||
initCore("solrconfig.xml", "schema.xml");
|
initCore("solrconfig.xml", "schema.xml");
|
||||||
parser = new SolrRequestParsers( h.getCore().getSolrConfig() );
|
parser = new SolrRequestParsers( h.getCore().getSolrConfig() );
|
||||||
}
|
}
|
||||||
|
@ -240,10 +232,9 @@ public class SolrRequestParserTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
for( String contentType : ct ) {
|
for( String contentType : ct ) {
|
||||||
HttpServletRequest request = getMock("/solr/select", contentType, postBytes.length);
|
HttpServletRequest request = getMock("/solr/select", contentType, postBytes.length);
|
||||||
expect(request.getMethod()).andReturn("POST").anyTimes();
|
when(request.getMethod()).thenReturn("POST");
|
||||||
expect(request.getQueryString()).andReturn(getParams).anyTimes();
|
when(request.getQueryString()).thenReturn(getParams);
|
||||||
expect(request.getInputStream()).andReturn(new ByteServletInputStream(postBytes));
|
when(request.getInputStream()).thenReturn(new ByteServletInputStream(postBytes));
|
||||||
replay(request);
|
|
||||||
|
|
||||||
MultipartRequestParser multipart = new MultipartRequestParser( 2048 );
|
MultipartRequestParser multipart = new MultipartRequestParser( 2048 );
|
||||||
RawRequestParser raw = new RawRequestParser();
|
RawRequestParser raw = new RawRequestParser();
|
||||||
|
@ -255,6 +246,8 @@ public class SolrRequestParserTest extends SolrTestCaseJ4 {
|
||||||
assertEquals( "contentType: "+contentType, "hello", p.get("q") );
|
assertEquals( "contentType: "+contentType, "hello", p.get("q") );
|
||||||
assertEquals( "contentType: "+contentType, "\u00FC", p.get("qt") );
|
assertEquals( "contentType: "+contentType, "\u00FC", p.get("qt") );
|
||||||
assertArrayEquals( "contentType: "+contentType, new String[]{"foo","bar"}, p.getParams("dup") );
|
assertArrayEquals( "contentType: "+contentType, new String[]{"foo","bar"}, p.getParams("dup") );
|
||||||
|
|
||||||
|
verify(request).getInputStream();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,10 +293,9 @@ public class SolrRequestParserTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
// Set up the expected behavior
|
// Set up the expected behavior
|
||||||
HttpServletRequest request = getMock("/solr/select", contentType, postBytes.length);
|
HttpServletRequest request = getMock("/solr/select", contentType, postBytes.length);
|
||||||
expect(request.getMethod()).andReturn("POST").anyTimes();
|
when(request.getMethod()).thenReturn("POST");
|
||||||
expect(request.getQueryString()).andReturn(getParams).anyTimes();
|
when(request.getQueryString()).thenReturn(getParams);
|
||||||
expect(request.getInputStream()).andReturn(new ByteServletInputStream(postBytes));
|
when(request.getInputStream()).thenReturn(new ByteServletInputStream(postBytes));
|
||||||
replay(request);
|
|
||||||
|
|
||||||
MultipartRequestParser multipart = new MultipartRequestParser( 2048 );
|
MultipartRequestParser multipart = new MultipartRequestParser( 2048 );
|
||||||
RawRequestParser raw = new RawRequestParser();
|
RawRequestParser raw = new RawRequestParser();
|
||||||
|
@ -316,6 +308,8 @@ public class SolrRequestParserTest extends SolrTestCaseJ4 {
|
||||||
assertEquals( "contentType: "+contentType, "\u00FC", p.get("qt") );
|
assertEquals( "contentType: "+contentType, "\u00FC", p.get("qt") );
|
||||||
assertEquals( "contentType: "+contentType, "\u00FC", p.get("qt2") );
|
assertEquals( "contentType: "+contentType, "\u00FC", p.get("qt2") );
|
||||||
assertArrayEquals( "contentType: "+contentType, new String[]{"foo","\u00FC","bar"}, p.getParams("dup") );
|
assertArrayEquals( "contentType: "+contentType, new String[]{"foo","\u00FC","bar"}, p.getParams("dup") );
|
||||||
|
|
||||||
|
verify(request).getInputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -329,10 +323,8 @@ public class SolrRequestParserTest extends SolrTestCaseJ4 {
|
||||||
large.append('&').append(large);
|
large.append('&').append(large);
|
||||||
}
|
}
|
||||||
HttpServletRequest request = getMock("/solr/select", "application/x-www-form-urlencoded", -1);
|
HttpServletRequest request = getMock("/solr/select", "application/x-www-form-urlencoded", -1);
|
||||||
expect(request.getMethod()).andReturn("POST").anyTimes();
|
when(request.getMethod()).thenReturn("POST");
|
||||||
expect(request.getQueryString()).andReturn(null).anyTimes();
|
when(request.getInputStream()).thenReturn(new ByteServletInputStream(large.toString().getBytes(StandardCharsets.US_ASCII)));
|
||||||
expect(request.getInputStream()).andReturn(new ByteServletInputStream(large.toString().getBytes(StandardCharsets.US_ASCII)));
|
|
||||||
replay(request);
|
|
||||||
|
|
||||||
FormDataRequestParser formdata = new FormDataRequestParser( limitKBytes );
|
FormDataRequestParser formdata = new FormDataRequestParser( limitKBytes );
|
||||||
try {
|
try {
|
||||||
|
@ -342,15 +334,16 @@ public class SolrRequestParserTest extends SolrTestCaseJ4 {
|
||||||
assertTrue(solre.getMessage().contains("upload limit"));
|
assertTrue(solre.getMessage().contains("upload limit"));
|
||||||
assertEquals(400, solre.code());
|
assertEquals(400, solre.code());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
verify(request).getInputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParameterIncompatibilityException1() throws Exception
|
public void testParameterIncompatibilityException1() throws Exception
|
||||||
{
|
{
|
||||||
HttpServletRequest request = getMock("/solr/select", "application/x-www-form-urlencoded", 100);
|
HttpServletRequest request = getMock("/solr/select", "application/x-www-form-urlencoded", 100);
|
||||||
expect(request.getQueryString()).andReturn(null).anyTimes();
|
|
||||||
// we emulate Jetty that returns empty stream when parameters were parsed before:
|
// we emulate Jetty that returns empty stream when parameters were parsed before:
|
||||||
expect(request.getInputStream()).andReturn(new ServletInputStream() {
|
when(request.getInputStream()).thenReturn(new ServletInputStream() {
|
||||||
@Override public int read() { return -1; }
|
@Override public int read() { return -1; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -368,7 +361,6 @@ public class SolrRequestParserTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
replay(request);
|
|
||||||
|
|
||||||
FormDataRequestParser formdata = new FormDataRequestParser( 2048 );
|
FormDataRequestParser formdata = new FormDataRequestParser( 2048 );
|
||||||
try {
|
try {
|
||||||
|
@ -378,17 +370,16 @@ public class SolrRequestParserTest extends SolrTestCaseJ4 {
|
||||||
assertTrue(solre.getMessage().startsWith("Solr requires that request parameters"));
|
assertTrue(solre.getMessage().startsWith("Solr requires that request parameters"));
|
||||||
assertEquals(500, solre.code());
|
assertEquals(500, solre.code());
|
||||||
}
|
}
|
||||||
|
verify(request).getInputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParameterIncompatibilityException2() throws Exception
|
public void testParameterIncompatibilityException2() throws Exception
|
||||||
{
|
{
|
||||||
HttpServletRequest request = getMock("/solr/select", "application/x-www-form-urlencoded", 100);
|
HttpServletRequest request = getMock("/solr/select", "application/x-www-form-urlencoded", 100);
|
||||||
expect(request.getMethod()).andReturn("POST").anyTimes();
|
when(request.getMethod()).thenReturn("POST");
|
||||||
expect(request.getQueryString()).andReturn(null).anyTimes();
|
|
||||||
// we emulate Tomcat that throws IllegalStateException when parameters were parsed before:
|
// we emulate Tomcat that throws IllegalStateException when parameters were parsed before:
|
||||||
expect(request.getInputStream()).andThrow(new IllegalStateException());
|
when(request.getInputStream()).thenThrow(new IllegalStateException());
|
||||||
replay(request);
|
|
||||||
|
|
||||||
FormDataRequestParser formdata = new FormDataRequestParser( 2048 );
|
FormDataRequestParser formdata = new FormDataRequestParser( 2048 );
|
||||||
try {
|
try {
|
||||||
|
@ -398,22 +389,22 @@ public class SolrRequestParserTest extends SolrTestCaseJ4 {
|
||||||
assertTrue(solre.getMessage().startsWith("Solr requires that request parameters"));
|
assertTrue(solre.getMessage().startsWith("Solr requires that request parameters"));
|
||||||
assertEquals(500, solre.code());
|
assertEquals(500, solre.code());
|
||||||
}
|
}
|
||||||
|
verify(request).getInputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddHttpRequestToContext() throws Exception {
|
public void testAddHttpRequestToContext() throws Exception {
|
||||||
HttpServletRequest request = getMock("/solr/select", null, -1);
|
HttpServletRequest request = getMock("/solr/select", null, -1);
|
||||||
expect(request.getMethod()).andReturn("GET").anyTimes();
|
when(request.getMethod()).thenReturn("GET");
|
||||||
expect(request.getQueryString()).andReturn("q=title:solr").anyTimes();
|
when(request.getQueryString()).thenReturn("q=title:solr");
|
||||||
Map<String, String> headers = new HashMap<>();
|
Map<String, String> headers = new HashMap<>();
|
||||||
headers.put("X-Forwarded-For", "10.0.0.1");
|
headers.put("X-Forwarded-For", "10.0.0.1");
|
||||||
expect(request.getHeaderNames()).andReturn(new Vector<>(headers.keySet()).elements()).anyTimes();
|
when(request.getHeaderNames()).thenReturn(new Vector<>(headers.keySet()).elements());
|
||||||
for(Map.Entry<String,String> entry:headers.entrySet()) {
|
for(Map.Entry<String,String> entry:headers.entrySet()) {
|
||||||
Vector<String> v = new Vector<>();
|
Vector<String> v = new Vector<>();
|
||||||
v.add(entry.getValue());
|
v.add(entry.getValue());
|
||||||
expect(request.getHeaders(entry.getKey())).andReturn(v.elements()).anyTimes();
|
when(request.getHeaders(entry.getKey())).thenReturn(v.elements());
|
||||||
}
|
}
|
||||||
replay(request);
|
|
||||||
|
|
||||||
SolrRequestParsers parsers = new SolrRequestParsers(h.getCore().getSolrConfig());
|
SolrRequestParsers parsers = new SolrRequestParsers(h.getCore().getSolrConfig());
|
||||||
assertFalse(parsers.isAddRequestHeadersToContext());
|
assertFalse(parsers.isAddRequestHeadersToContext());
|
||||||
|
@ -429,10 +420,7 @@ public class SolrRequestParserTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
public void testPostMissingContentType() throws Exception {
|
public void testPostMissingContentType() throws Exception {
|
||||||
HttpServletRequest request = getMock();
|
HttpServletRequest request = getMock();
|
||||||
expect(request.getMethod()).andReturn("POST").anyTimes();
|
when(request.getMethod()).thenReturn("POST");
|
||||||
expect(request.getQueryString()).andReturn(null).anyTimes();
|
|
||||||
expect(request.getHeader(anyObject())).andReturn(null).anyTimes();
|
|
||||||
replay(request);
|
|
||||||
|
|
||||||
SolrRequestParsers parsers = new SolrRequestParsers(h.getCore().getSolrConfig());
|
SolrRequestParsers parsers = new SolrRequestParsers(h.getCore().getSolrConfig());
|
||||||
try {
|
try {
|
||||||
|
@ -470,20 +458,16 @@ public class SolrRequestParserTest extends SolrTestCaseJ4 {
|
||||||
String contentType = "application/x-www-form-urlencoded";
|
String contentType = "application/x-www-form-urlencoded";
|
||||||
int contentLength = -1; // does this mean auto-detect?
|
int contentLength = -1; // does this mean auto-detect?
|
||||||
|
|
||||||
HttpServletRequest request = createMock(HttpServletRequest.class);
|
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||||
expect(request.getHeader("User-Agent")).andReturn(userAgent).anyTimes();
|
when(request.getHeader("User-Agent")).thenReturn(userAgent);
|
||||||
expect(request.getHeader("Content-Length")).andReturn(null).anyTimes();
|
when(request.getRequestURI()).thenReturn(uri);
|
||||||
expect(request.getRequestURI()).andReturn(uri).anyTimes();
|
when(request.getContentType()).thenReturn(contentType);
|
||||||
expect(request.getContentType()).andReturn(contentType).anyTimes();
|
when(request.getContentLength()).thenReturn(contentLength);
|
||||||
expect(request.getContentLength()).andReturn(contentLength).anyTimes();
|
|
||||||
expect(request.getAttribute(SolrRequestParsers.REQUEST_TIMER_SERVLET_ATTRIBUTE)).andReturn(null).anyTimes();
|
|
||||||
|
|
||||||
expect(request.getMethod()).andReturn(method).anyTimes();
|
when(request.getMethod()).thenReturn(method);
|
||||||
// we dont pass a content-length to let the security mechanism limit it:
|
// we dont pass a content-length to let the security mechanism limit it:
|
||||||
expect(request.getQueryString()).andReturn("foo=1&bar=2").anyTimes();
|
when(request.getQueryString()).thenReturn("foo=1&bar=2");
|
||||||
expect(request.getInputStream()).andReturn(new ByteServletInputStream(body.getBytes(StandardCharsets.US_ASCII)));
|
when(request.getInputStream()).thenReturn(new ByteServletInputStream(body.getBytes(StandardCharsets.US_ASCII)));
|
||||||
expect(request.getAttribute(EasyMock.anyObject(String.class))).andReturn(null).anyTimes();
|
|
||||||
replay(request);
|
|
||||||
|
|
||||||
SolrRequestParsers parsers = new SolrRequestParsers(h.getCore().getSolrConfig());
|
SolrRequestParsers parsers = new SolrRequestParsers(h.getCore().getSolrConfig());
|
||||||
SolrQueryRequest req = parsers.parse(h.getCore(), "/select", request);
|
SolrQueryRequest req = parsers.parse(h.getCore(), "/select", request);
|
||||||
|
@ -506,21 +490,19 @@ public class SolrRequestParserTest extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
|
|
||||||
req.close();
|
req.close();
|
||||||
|
verify(request).getInputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public HttpServletRequest getMock() {
|
public HttpServletRequest getMock() {
|
||||||
return getMock("/solr/select", null, -1);
|
return getMock("/solr/select", null, -1);
|
||||||
// return getMock("/solr/select", "application/x-www-form-urlencoded");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpServletRequest getMock(String uri, String contentType, int contentLength) {
|
public HttpServletRequest getMock(String uri, String contentType, int contentLength) {
|
||||||
HttpServletRequest request = createMock(HttpServletRequest.class);
|
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||||
expect(request.getHeader("User-Agent")).andReturn(null).anyTimes();
|
when(request.getRequestURI()).thenReturn(uri);
|
||||||
expect(request.getRequestURI()).andReturn(uri).anyTimes();
|
when(request.getContentType()).thenReturn(contentType);
|
||||||
expect(request.getContentType()).andReturn(contentType).anyTimes();
|
when(request.getContentLength()).thenReturn(contentLength);
|
||||||
expect(request.getContentLength()).andReturn(contentLength).anyTimes();
|
|
||||||
expect(request.getAttribute(EasyMock.anyObject(String.class))).andReturn(null).anyTimes();
|
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
f28a4c31c330f95c9acbf1108cea19952b5c496f
|
|
|
@ -1,17 +0,0 @@
|
||||||
EasyMock 2 License (MIT License)
|
|
||||||
|
|
||||||
Copyright (c) 2001-2006 OFFIS, Tammo Freese.
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
||||||
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
|
||||||
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject
|
|
||||||
to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
||||||
portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
||||||
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
||||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
||||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
||||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
@ -40,8 +40,9 @@
|
||||||
<dependency org="org.slf4j" name="jcl-over-slf4j" rev="${/org.slf4j/jcl-over-slf4j}" conf="compile"/>
|
<dependency org="org.slf4j" name="jcl-over-slf4j" rev="${/org.slf4j/jcl-over-slf4j}" conf="compile"/>
|
||||||
|
|
||||||
<dependency org="org.slf4j" name="slf4j-log4j12" rev="${/org.slf4j/slf4j-log4j12}" conf="test"/>
|
<dependency org="org.slf4j" name="slf4j-log4j12" rev="${/org.slf4j/slf4j-log4j12}" conf="test"/>
|
||||||
<dependency org="org.easymock" name="easymock" rev="${/org.easymock/easymock}" conf="test"/>
|
|
||||||
<dependency org="cglib" name="cglib-nodep" rev="${/cglib/cglib-nodep}" conf="test"/>
|
<dependency org="org.mockito" name="mockito-core" rev="${/org.mockito/mockito-core}" conf="test"/>
|
||||||
|
<dependency org="net.bytebuddy" name="byte-buddy" rev="${/net.bytebuddy/byte-buddy}" conf="test"/>
|
||||||
<dependency org="org.objenesis" name="objenesis" rev="${/org.objenesis/objenesis}" conf="test"/>
|
<dependency org="org.objenesis" name="objenesis" rev="${/org.objenesis/objenesis}" conf="test"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,24 +31,17 @@ import java.util.function.Function;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import org.apache.http.NoHttpResponseException;
|
import org.apache.http.NoHttpResponseException;
|
||||||
import org.apache.lucene.util.Constants;
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.client.solrj.request.UpdateRequest;
|
import org.apache.solr.client.solrj.request.UpdateRequest;
|
||||||
import org.apache.solr.common.cloud.ClusterState;
|
import org.apache.solr.common.cloud.ClusterState;
|
||||||
import org.apache.solr.common.cloud.DocCollection;
|
import org.apache.solr.common.cloud.DocCollection;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.easymock.EasyMock;
|
import static org.mockito.Mockito.*;
|
||||||
import org.junit.BeforeClass;
|
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
public class CloudSolrClientCacheTest extends SolrTestCaseJ4 {
|
public class CloudSolrClientCacheTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void beforeClass() throws Exception {
|
|
||||||
assumeFalse("SOLR-9893: EasyMock does not work with Java 9", Constants.JRE_IS_MINIMUM_JAVA9);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testCaching() throws Exception {
|
public void testCaching() throws Exception {
|
||||||
String collName = "gettingstarted";
|
String collName = "gettingstarted";
|
||||||
Set<String> livenodes = new HashSet<>();
|
Set<String> livenodes = new HashSet<>();
|
||||||
|
@ -108,12 +101,10 @@ public class CloudSolrClientCacheTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
|
|
||||||
private LBHttpSolrClient getMockLbHttpSolrClient(Map<String, Function> responses) throws Exception {
|
private LBHttpSolrClient getMockLbHttpSolrClient(Map<String, Function> responses) throws Exception {
|
||||||
LBHttpSolrClient mockLbclient = EasyMock.createMock(LBHttpSolrClient.class);
|
LBHttpSolrClient mockLbclient = mock(LBHttpSolrClient.class);
|
||||||
EasyMock.reset(mockLbclient);
|
|
||||||
|
|
||||||
mockLbclient.request(EasyMock.anyObject(LBHttpSolrClient.Req.class));
|
when(mockLbclient.request(any(LBHttpSolrClient.Req.class))).then(invocationOnMock -> {
|
||||||
EasyMock.expectLastCall().andAnswer(() -> {
|
LBHttpSolrClient.Req req = invocationOnMock.getArgument(0);
|
||||||
LBHttpSolrClient.Req req = (LBHttpSolrClient.Req) EasyMock.getCurrentArguments()[0];
|
|
||||||
Function f = responses.get("request");
|
Function f = responses.get("request");
|
||||||
if (f == null) return null;
|
if (f == null) return null;
|
||||||
Object res = f.apply(null);
|
Object res = f.apply(null);
|
||||||
|
@ -122,12 +113,7 @@ public class CloudSolrClientCacheTest extends SolrTestCaseJ4 {
|
||||||
rsp.rsp = (NamedList<Object>) res;
|
rsp.rsp = (NamedList<Object>) res;
|
||||||
rsp.server = req.servers.get(0);
|
rsp.server = req.servers.get(0);
|
||||||
return rsp;
|
return rsp;
|
||||||
}).anyTimes();
|
});
|
||||||
|
|
||||||
mockLbclient.getHttpClient();
|
|
||||||
EasyMock.expectLastCall().andAnswer(() -> null).anyTimes();
|
|
||||||
|
|
||||||
EasyMock.replay(mockLbclient);
|
|
||||||
return mockLbclient;
|
return mockLbclient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue