Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not optimize after commit #37

Merged
merged 2 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 28 additions & 27 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/Listener/JobEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,9 @@ public function postFlush(PostFlushEventArgs $eventArgs)
$client->deleteByIds($this->entityToDocumentFilter->getDocumentIds($job));
}

// commit to index & optimize it
// commit to index
$client = $this->getSolrClient();
$client->commit(true, false);
$client->optimize(1, true, false);

// clear arrays. There could be multiple flushs per requests and we do not want
// to process already processed entities.
Expand Down
48 changes: 23 additions & 25 deletions test/SolrTest/Listener/JobEventSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,19 @@ protected function setUp(): void
->getMock();
$options->method('getJobsPath')
->willReturn('/some/path');

$this->client = $this->getMockBuilder(\SolrClient::class)
->disableOriginalConstructor()
->getMock();

$this->manager = $this->getMockBuilder(Manager::class)
->disableOriginalConstructor()
->getMock();
$this->manager->method('getClient')
->willReturn($this->client);
$this->manager->method('getOptions')
->willReturn($options);

$this->entityToDocumentFilter = $this->getMockBuilder(EntityToDocumentFilter::class)
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -137,17 +137,17 @@ public function testPrePersistShouldNotProcessNonJobDocument()
->getMock();
$job->expects($this->never())
->method('isActive');

$event = $this->getMockBuilder(PreUpdateEventArgs::class)
->disableOriginalConstructor()
->getMock();
$event->expects($this->once())
->method('getDocument')
->willReturn($job);

$this->subscriber->prePersist($event);
}

/**
* @param string $status
* @param bool $shouldBeAdded
Expand Down Expand Up @@ -187,7 +187,7 @@ public function testPreUpdateShouldNotProcessNonJobDocument()
->method('getDocument');
$event->expects($this->never())
->method('hasChangedField');

$this->subscriber->preUpdate($event);
}

Expand Down Expand Up @@ -241,7 +241,7 @@ public function testPreUpdateWithChangedStatus($status, $shouldBeAdded, $shouldB

$subscriber = $this->subscriber;
$subscriber->preUpdate($event);

if ($shouldBeAdded) {
$this->assertContains($job, $subscriber->getAdd());
} else {
Expand All @@ -254,7 +254,7 @@ public function testPreUpdateWithChangedStatus($status, $shouldBeAdded, $shouldB
$this->assertNotContains($job, $subscriber->getDelete());
}
}

/**
* @covers ::postFlush()
*/
Expand All @@ -266,14 +266,14 @@ public function testPostFlushWithNoJobsToProcess()
->getMock();
$subscriber->expects($this->never())
->method('getSolrClient');

$event = $this->getMockBuilder(PostFlushEventArgs::class)
->disableOriginalConstructor()
->getMock();

$subscriber->postFlush($event);
}

/**
* @param string $status
* @param bool $shouldBeAdded
Expand All @@ -296,47 +296,45 @@ public function testPostFlushWithJobsToProcess($status, $shouldBeAdded, $shouldB
->method('hasChangedField')
->with($this->equalTo('status'))
->willReturn(true);

$this->subscriber->preUpdate($event);

if ($shouldBeAdded) {
$document = new SolrInputDocument();
$this->entityToDocumentFilter->expects($this->once())
->method('filter')
->with($this->identicalTo($job))
->willReturn($document);

$this->client->expects($this->once())
->method('addDocument')
->with($this->identicalTo($document));
}

if ($shouldBeDeleted) {
$ids = [1, 2, 3];
$this->entityToDocumentFilter->expects($this->once())
->method('getDocumentIds')
->with($this->identicalTo($job))
->willReturn($ids);

$this->client->expects($this->once())
->method('deleteByIds')
->with($this->identicalTo($ids));
}

if ($shouldBeAdded || $shouldBeDeleted) {
$this->client->expects($this->once())
->method('commit');
$this->client->expects($this->once())
->method('optimize');
}

$event = $this->getMockBuilder(PostFlushEventArgs::class)
->disableOriginalConstructor()
->getMock();

$this->subscriber->postFlush($event);
}

/**
* @covers ::factory()
*/
Expand All @@ -350,10 +348,10 @@ public function testFactory()
->withConsecutive([$this->equalTo('Solr/Options/Module')],
[$this->equalTo('Solr/Manager')])
->will($this->onConsecutiveCalls($options,$this->manager));

$this->assertInstanceOf(JobEventSubscriber::class, JobEventSubscriber::factory($container));
}

/**
* @return array
*/
Expand Down