Skip to content

Commit

Permalink
do not optimize after commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cbleek committed Sep 22, 2020
1 parent aa86dfe commit 8596d78
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
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

0 comments on commit 8596d78

Please sign in to comment.