Skip to content

Commit

Permalink
Solr 9.4 → 9.5 for integration tests (solariumphp#1121)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomascorthals authored Mar 11, 2024
1 parent ae4ea59 commit c9ba8b5
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 68 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ jobs:
ref: branch_8_11
path: lucene-solr

- name: Checkout solr 9.4
- name: Checkout solr 9.5
if: matrix.solr == 9
uses: actions/checkout@v4
with:
repository: apache/solr
ref: branch_9_4
ref: branch_9_5
path: lucene-solr

- name: Start Solr ${{ matrix.solr }} in ${{ matrix.mode }} mode
Expand Down
94 changes: 33 additions & 61 deletions tests/Integration/AbstractTechproductsTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use PHPUnit\Framework\TestCase;
use Solarium\Component\ComponentAwareQueryInterface;
use Solarium\Component\Highlighting\Highlighting;
use Solarium\Component\QueryInterface;
use Solarium\Component\QueryTraits\GroupingTrait;
use Solarium\Component\QueryTraits\TermsTrait;
use Solarium\Component\Result\Facet\Pivot\PivotItem;
Expand Down Expand Up @@ -47,8 +46,6 @@
use Solarium\QueryType\Luke\Result\Fields\FieldInfo as LukeFieldInfo;
use Solarium\QueryType\Luke\Result\Index\Index as LukeIndexResult;
use Solarium\QueryType\Luke\Result\Schema\Schema as LukeSchemaResult;
use Solarium\QueryType\ManagedResources\Query\AbstractQuery as AbstractManagedResourceQuery;
use Solarium\QueryType\ManagedResources\Query\Command\AbstractAdd as AbstractAddCommand;
use Solarium\QueryType\ManagedResources\Query\Stopwords as StopwordsQuery;
use Solarium\QueryType\ManagedResources\Query\Synonyms as SynonymsQuery;
use Solarium\QueryType\ManagedResources\Query\Synonyms\Synonyms;
Expand All @@ -62,9 +59,6 @@
use Solarium\QueryType\Update\RequestBuilder\Xml as XmlUpdateRequestBuilder;
use Solarium\Support\Utility;
use Solarium\Tests\Integration\Plugin\EventTimer;
use Solarium\Tests\Integration\Query\CustomQueryInterfaceQuery;
use Solarium\Tests\Integration\Query\CustomSelfQuery;
use Solarium\Tests\Integration\Query\CustomStaticQuery;
use Symfony\Contracts\EventDispatcher\Event;
use TRegx\PhpUnit\DataProviders\DataProvider;

Expand Down Expand Up @@ -5179,9 +5173,10 @@ public function testManagedResources()
* @see https://issues.apache.org/jira/browse/SOLR-6853
* @see https://github.com/solariumphp/solarium/pull/742
*
* @dataProvider managedResourcesSolr6853Provider
* @testWith ["stopwords"]
* ["synonyms"]
*/
public function testManagedResourcesSolr6853(string $resourceType, AbstractManagedResourceQuery $query, AbstractAddCommand $add)
public function testManagedResourcesSolr6853(string $resourceType)
{
// unique name is necessary for Stopwords to avoid running into SOLR-14268
$uniqid = uniqid();
Expand All @@ -5197,10 +5192,36 @@ public function testManagedResourcesSolr6853(string $resourceType, AbstractManag
$nameDoubleEncoded = $uniqid.'test-%253A%252F%253F%2523%255B%255D%2540%2525%2520';
}

// unlike name, term can't contain a slash (SOLR-6853)
$term = 'test-:?#[]@% ';
$termSingleEncoded = 'test-%3A%3F%23%5B%5D%40%25%20';
$termDoubleEncoded = 'test-%253A%253F%2523%255B%255D%2540%2525%2520';
if (9 <= self::$solrVersion) {
$term = 'test-:/?#[]@% ';
$termSingleEncoded = 'test-%3A%2F%3F%23%5B%5D%40%25%20';
$termDoubleEncoded = 'test-%253A%252F%253F%2523%255B%255D%2540%2525%2520';
} else {
// Before Solr 9.4.1, term can't contain a slash (SOLR-6853)
$term = 'test-:?#[]@% ';
$termSingleEncoded = 'test-%3A%3F%23%5B%5D%40%25%20';
$termDoubleEncoded = 'test-%253A%253F%2523%255B%255D%2540%2525%2520';
}

switch ($resourceType) {
case 'stopwords':
$query = new StopwordsQuery();
$add = $query->createCommand($query::COMMAND_ADD);
$add->setStopwords([$term]);
break;
case 'synonyms':
$query = new SynonymsQuery();
$add = $query->createCommand($query::COMMAND_ADD);
$synonyms = new Synonyms();
$synonyms->setTerm($term);
$synonyms->setSynonyms(['foo', 'bar']);
$add->setSynonyms($synonyms);
break;
default:
// PHPStan needs these variables defined even though we never reach this branch
$query = null;
$add = null;
}

$compliantRequestBuilder = new CompliantManagedResourceRequestBuilder();
$actualRequestBuilder = new ResourceRequestBuilder();
Expand Down Expand Up @@ -5317,29 +5338,6 @@ public function testManagedResourcesSolr6853(string $resourceType, AbstractManag
$this->assertFalse($result->getWasSuccessful());
}

public function managedResourcesSolr6853Provider(): array
{
$term = 'test-:?#[]@% ';
$data = [];

$query = new StopwordsQuery();
$add = $query->createCommand($query::COMMAND_ADD);
$add->setStopwords([$term]);

$data['stopwords'] = ['stopwords', $query, $add];

$query = new SynonymsQuery();
$add = $query->createCommand($query::COMMAND_ADD);
$synonyms = new Synonyms();
$synonyms->setTerm($term);
$synonyms->setSynonyms(['foo', 'bar']);
$add->setSynonyms($synonyms);

$data['synonyms'] = ['synonyms', $query, $add];

return $data;
}

public function testGetBodyOnHttpError()
{
/** @var \Solarium\Core\Query\Status4xxNoExceptionInterface $query */
Expand Down Expand Up @@ -5393,32 +5391,6 @@ public function testEventDispatching()

self::$client->removePlugin('eventtimer');
}

/**
* Test the various return types that are valid for custom query classes that
* override the {@see \Solarium\Component\QueryTrait::setQuery()} method.
*
* If this test throws a fatal error, the return type of the parent might no
* longer be backward compatible with existing code that overrides it.
*
* @see https://github.com/solariumphp/solarium/issues/1097
*
* @dataProvider customQueryClassProvider
*/
public function testCustomQueryClassSetQueryReturnType(string $queryClass)
{
$query = new $queryClass();
$this->assertInstanceOf(QueryInterface::class, $query->setQuery('*:*'));
}

public function customQueryClassProvider(): array
{
return [
[CustomStaticQuery::class],
[CustomSelfQuery::class],
[CustomQueryInterfaceQuery::class],
];
}
}

class GroupingTestQuery extends SelectQuery
Expand Down
29 changes: 24 additions & 5 deletions tests/Integration/ConnectionReuseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ class ConnectionReuseTest extends TestCase
*/
protected static $isNewLoggingApi;

/**
* Are we running against a v2 logging API with a known bug (SOLR-17176l)?
*
* @var bool
*/
protected static $isBuggyLoggingApi;

/**
* Original org.eclipse.jetty.io.AbstractConnection log level to restore after the testcase.
*
Expand Down Expand Up @@ -68,6 +75,7 @@ public static function setUpBeforeClass(): void
self::$client = TestClientFactory::createWithPsr18Adapter(self::$config);

// determine if we're running against a version of Solr that uses the tweaked v2 logging API (SOLR-16458)
// determine if we're running against a version of Solr with a known bug in the v2 logging API (SOLR-17176l)
$query = self::$client->createApi([
'version' => Request::API_V1,
'handler' => 'admin/info/system',
Expand All @@ -77,6 +85,7 @@ public static function setUpBeforeClass(): void

$solrSpecVersion = $system['lucene']['solr-spec-version'];
self::$isNewLoggingApi = version_compare($solrSpecVersion, '9.3', '>=');
self::$isBuggyLoggingApi = version_compare($solrSpecVersion, '9.5', '>=');

// get the current log level to restore afterwards to avoid excessive logging in other testcases
$query = self::$client->createApi([
Expand Down Expand Up @@ -228,16 +237,26 @@ public function testConnectionReuse(string $createFunction, int $expectedCount)
$client->execute($query);
}

$query = $client->createApi([
'version' => Request::API_V2,
'handler' => self::$isNewLoggingApi ? 'node/logging/messages' : 'node/logging',
]);
if (self::$isBuggyLoggingApi) {
// fallback to v1 logging API to work around SOLR-17176
$apiOptions = [
'version' => Request::API_V1,
'handler' => 'admin/info/logging',
];
} else {
$apiOptions = [
'version' => Request::API_V2,
'handler' => self::$isNewLoggingApi ? 'node/logging/messages' : 'node/logging',
];
}

$query = $client->createApi($apiOptions);
$query->addParam('since', self::$since);
$result = $client->execute($query);
$data = $result->getData();
self::$since = $data['info']['last'];

$connections = $this->extractConnections(self::$isNewLoggingApi ? $data['history'] : $data['history']['docs']);
$connections = $this->extractConnections(self::$isNewLoggingApi && !self::$isBuggyLoggingApi ? $data['history'] : $data['history']['docs']);

// The count is off-by-1 with an additional connection for one of the tests:
// - the request for node/logging without reuse is included in the count without reuse in most tests in a workflow;
Expand Down
1 change: 1 addition & 0 deletions tests/Integration/Proxy/AbstractProxyTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Abstract test for connecting through a proxy.
*
* @group integration
* @group proxy
*/
abstract class AbstractProxyTestCase extends TestCase
{
Expand Down
1 change: 1 addition & 0 deletions tests/Integration/Proxy/CurlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Test connecting through a proxy with the Curl adapter.
*
* @group integration
* @group proxy
*/
class CurlTest extends AbstractProxyTestCase
{
Expand Down
1 change: 1 addition & 0 deletions tests/Integration/Proxy/CustomizedCurlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Test connecting through a proxy with a customized Curl adapter that sets the proxy options differently.
*
* @group integration
* @group proxy
*/
class CustomizedCurlTest extends CurlTest
{
Expand Down
1 change: 1 addition & 0 deletions tests/Integration/Proxy/CustomizedHttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Test connecting through a proxy with a customized Http adapter that sets the proxy options differently.
*
* @group integration
* @group proxy
*/
class CustomizedHttpTest extends HttpTest
{
Expand Down
1 change: 1 addition & 0 deletions tests/Integration/Proxy/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Test connecting through a proxy with the Http adapter.
*
* @group integration
* @group proxy
*/
class HttpTest extends AbstractProxyTestCase
{
Expand Down
35 changes: 35 additions & 0 deletions tests/Integration/Query/CustomQueryClassTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Solarium\Tests\Integration\Query;

use PHPUnit\Framework\TestCase;
use Solarium\Component\QueryInterface;

class CustomQueryClassTest extends TestCase
{
/**
* Test the various return types that are valid for custom query classes that
* override the {@see \Solarium\Component\QueryTrait::setQuery()} method.
*
* If this test throws a fatal error, the return type of the parent might no
* longer be backward compatible with existing code that overrides it.
*
* @see https://github.com/solariumphp/solarium/issues/1097
*
* @dataProvider customQueryClassProvider
*/
public function testCustomQueryClassSetQueryReturnType(string $queryClass)
{
$query = new $queryClass();
$this->assertInstanceOf(QueryInterface::class, $query->setQuery('*:*'));
}

public function customQueryClassProvider(): array
{
return [
[CustomStaticQuery::class],
[CustomSelfQuery::class],
[CustomQueryInterfaceQuery::class],
];
}
}

0 comments on commit c9ba8b5

Please sign in to comment.