Skip to content

Commit e5d9c3d

Browse files
committed
Merge branch 'pr/732' into 3.0.x
2 parents 81f5f98 + 906e2e0 commit e5d9c3d

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

CHANGELOG-3.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ To generate a changelog summary since the last version, run
1515
* 3.0.8 (Unreleased)
1616

1717
* Fixed handling of empty indexes #760
18+
* Added support for `connectionStrategy` Elastica configuration #732
1819

1920
* 3.0.7 (2015-01-21)
2021

DependencyInjection/Configuration.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ private function addClientsSection(ArrayNodeDefinition $rootNode)
8484
return $v;
8585
})
8686
->end()
87+
// Elastica names its properties with camel case, support both
88+
->beforeNormalization()
89+
->ifTrue(function ($v) { return isset($v['connection_strategy']); })
90+
->then(function ($v) {
91+
$v['connectionStrategy'] = $v['connection_strategy'];
92+
unset($v['connection_strategy']);
93+
94+
return $v;
95+
})
96+
->end()
8797
// If there is no connections array key defined, assume a single connection.
8898
->beforeNormalization()
8999
->ifTrue(function ($v) { return is_array($v) && !array_key_exists('connections', $v); })
@@ -124,6 +134,7 @@ private function addClientsSection(ArrayNodeDefinition $rootNode)
124134
->end()
125135
->scalarNode('timeout')->end()
126136
->scalarNode('headers')->end()
137+
->scalarNode('connectionStrategy')->defaultValue('Simple')->end()
127138
->end()
128139
->end()
129140
->end()

Resources/doc/cookbook/multiple-connections.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ fos_elastica:
1111
connections:
1212
- url: http://es1.example.net:9200
1313
- url: http://es2.example.net:9200
14+
connection_strategy: RoundRobin
1415
```
1516
17+
Elastica allows for definition of different connection strategies and by default
18+
supports `RoundRobin` and `Simple`. You can see definitions for these strategies
19+
in the `Elastica\Connection\Strategy` namespace.
20+
1621
For more information on Elastica clustering see http://elastica.io/getting-started/installation.html#section-connect-cluster

Tests/Functional/ClientTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the FOSElasticaBundle project.
5+
*
6+
* (c) Tim Nagel <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace FOS\ElasticaBundle\Tests\Functional;
13+
14+
use Symfony\Bundle\FrameworkBundle\Client;
15+
16+
/**
17+
* @group functional
18+
*/
19+
class ClientTest extends WebTestCase
20+
{
21+
public function testContainerSource()
22+
{
23+
$client = $this->createClient(array('test_case' => 'Basic'));
24+
25+
$es = $client->getContainer()->get('fos_elastica.client.default');
26+
$this->assertInstanceOf('Elastica\\Connection\\Strategy\\RoundRobin', $es->getConnectionStrategy());
27+
28+
$es = $client->getContainer()->get('fos_elastica.client.second_server');
29+
$this->assertInstanceOf('Elastica\\Connection\\Strategy\\RoundRobin', $es->getConnectionStrategy());
30+
31+
$es = $client->getContainer()->get('fos_elastica.client.third');
32+
$this->assertInstanceOf('Elastica\\Connection\\Strategy\\Simple', $es->getConnectionStrategy());
33+
}
34+
35+
protected function setUp()
36+
{
37+
parent::setUp();
38+
39+
$this->deleteTmpDir('Basic');
40+
}
41+
42+
protected function tearDown()
43+
{
44+
parent::tearDown();
45+
46+
$this->deleteTmpDir('Basic');
47+
}
48+
}

Tests/Functional/app/Basic/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ fos_elastica:
1515
- url: http://localhost:9200
1616
- host: localhost
1717
port: 9200
18+
connectionStrategy: RoundRobin
1819
second_server:
20+
connections:
21+
- url: http://localhost:9200
22+
connection_strategy: RoundRobin
23+
third:
1924
url: http://localhost:9200
2025
indexes:
2126
index:

0 commit comments

Comments
 (0)