diff --git a/ansible/provision.sh b/ansible/provision.sh index fef7faec8f..990be77880 100755 --- a/ansible/provision.sh +++ b/ansible/provision.sh @@ -39,17 +39,47 @@ fi # ---------------------------------------------------------------------------- -echo 'Waiting for elasticsearch server ready' -elasticsearch_ready() { - http_code=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:9200") - return $(test $http_code = "200") +all_nodes_available() { + curl -m 5 -s -o /dev/null "http://localhost:9200" && + curl -m 5 -s -o /dev/null "http://localhost:9201" + return $? } -while ! elasticsearch_ready; do - echo -n '.' - sleep 1s -done -# ---------------------------------------------------------------------------- -# Say bye +check_cluster() { + restarts_left=$1 + seconds_left=$2 + + if [ $seconds_left -eq 0 ]; then + if [ $restarts_left -eq 0 ]; then + echo "Cluster was restarted 10 times, but still not ready for phpunit. Build failed!" + return 1 + else + echo "Restart cluster. Restarts left: $restarts_left" + sudo service elasticsearch restart + check_cluster $(( $restarts_left - 1 )) 30 + return $? + fi + else + if all_nodes_available; then + echo "All nodes available. Sleep 30 seconds and try to check them again..." + if sleep 10s && all_nodes_available; then + echo "All nodes still available - cluster ready." + return 0 + else + echo "Some nodes were stopped during sleep. Trying cluster restart..." + check_cluster $restarts_left 0 + return $? + fi + else + echo "Some nodes still unavailable. Sleep 1 second and try to check them again. Seconds to start left: $seconds_left" + sleep 1s && check_cluster $restarts_left $(( $seconds_left - 1 )) + return $? + fi + fi +} -echo 'Done' +echo "Wait cluster start..." +if ! check_cluster 10 30; then + cat /var/log/elasticsearch/*.log + exit 1 +fi diff --git a/ansible/roles/elasticsearch/tasks/main.yml b/ansible/roles/elasticsearch/tasks/main.yml index 40cbf3b85f..ec60c8ba0d 100644 --- a/ansible/roles/elasticsearch/tasks/main.yml +++ b/ansible/roles/elasticsearch/tasks/main.yml @@ -80,7 +80,6 @@ with_items: - config-0.yml - config-1.yml - - config-2.yml - logging.yml notify: restart elasticsearch diff --git a/ansible/roles/elasticsearch/templates/config-2.yml b/ansible/roles/elasticsearch/templates/config-2.yml deleted file mode 100644 index 4ca43f3b8b..0000000000 --- a/ansible/roles/elasticsearch/templates/config-2.yml +++ /dev/null @@ -1,11 +0,0 @@ -{% extends "config-default.yml" %} - -{% block config %} - -http.port: 9202 -transport.tcp.port: 9302 -thrift.port: 9502 -memcached.port: 11213 -node.name: "Wolverine" - -{% endblock %} diff --git a/ansible/roles/elasticsearch/templates/config-default.yml b/ansible/roles/elasticsearch/templates/config-default.yml index f156fe657d..a83289d16e 100644 --- a/ansible/roles/elasticsearch/templates/config-default.yml +++ b/ansible/roles/elasticsearch/templates/config-default.yml @@ -1,30 +1,33 @@ {% block default_config %} -#################################### Index #################################### - index.number_of_shards: 2 index.number_of_replicas: 0 -#################################### Plugin ################################### +# Dont write data to hdd in tests +index.store.type: memory +# Required plugins plugin.mandatory: mapper-attachments, geocluster-facet, transport-thrift, transport-memcached -################################## UDP ######################################## - +# For bulk tests bulk.udp.enabled: true bulk.udp.bulk_actions: 5 -################################## Scripting ################################## - +# For script tests script.disable_dynamic: false -################################### Memory #################################### - +# Disable dynamic memory allocation bootstrap.mlockall: true +# Dont accept connections not from localhost +network.host: "127.0.0.1" + +# Limit threadpool by set number of available processors to 1 +# Without this, travis builds will be failed with OutOfMemory error +processors: 1 + {% endblock %} -################################### Node specific ############################# {% block config %} - +# Node specific config should be overwritten in child template {% endblock %} diff --git a/ansible/roles/elasticsearch/templates/elasticsearch.service b/ansible/roles/elasticsearch/templates/elasticsearch.service index 9ad02fc07d..0268e23011 100755 --- a/ansible/roles/elasticsearch/templates/elasticsearch.service +++ b/ansible/roles/elasticsearch/templates/elasticsearch.service @@ -76,7 +76,7 @@ export ES_JAVA_OPTS MAX_OPEN_FILES="65535" # Maximum amount of locked memory -MAX_LOCKED_MEMORY="$ES_HEAP_SIZE" +MAX_LOCKED_MEMORY="unlimited" # Elasticsearch log directory LOG_DIR="/var/log/$NAME" @@ -90,9 +90,6 @@ WORK_DIR="/tmp/$NAME" # Elasticsearch configuration directory CONF_DIR="/etc/$NAME" -# Maximum number of VMA (Virtual Memory Areas) a process can own -MAX_MAP_COUNT="262144" - # Define other required variables DAEMON="$ES_HOME/bin/elasticsearch" @@ -135,11 +132,9 @@ case "$1" in ulimit -l $MAX_LOCKED_MEMORY fi - if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ];then - sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT - fi + ulimit -s 1024 - for node in 0 1 2; do + for node in 0 1; do log_daemon_msg "Starting elasticsearch node #$node" PID_FILE="/var/run/$NAME-$node.pid" @@ -184,7 +179,7 @@ case "$1" in done ;; stop) - for node in 0 1 2; do + for node in 0 1; do log_daemon_msg "Stopping elasticsearch node #$node" PID_FILE="/var/run/$NAME-$node.pid" @@ -209,14 +204,14 @@ case "$1" in log_end_msg 0 ;; status) - for node in 0 1 2; do + for node in 0 1; do PID_FILE="/var/run/$NAME-$node.pid" status_of_proc -p $PID_FILE "Elasticsearch node #$node" "Elasticsearch node #$node" done exit 0 ;; restart|force-reload) - for node in 0 1 2; do + for node in 0 1; do PID_FILE="/var/run/$NAME-$node.pid" if [ -f "$PID_FILE" ]; then $0 stop diff --git a/changes.txt b/changes.txt index a85701eba4..71ee47e800 100644 --- a/changes.txt +++ b/changes.txt @@ -1,5 +1,8 @@ CHANGES +2015-02-11 +- Fixed issue with OutOfMemory exception in travis builds + 2015-01-27 - Exception\ElasticsearchException now can be catched like all other exceptions as Exception\ExceptionInterface diff --git a/test/lib/Elastica/Test/Aggregation/AvgTest.php b/test/lib/Elastica/Test/Aggregation/AvgTest.php index dc0800d1cf..da6dc93281 100644 --- a/test/lib/Elastica/Test/Aggregation/AvgTest.php +++ b/test/lib/Elastica/Test/Aggregation/AvgTest.php @@ -11,7 +11,7 @@ class AvgTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex('avg'); + $this->_index = $this->_createIndex(); $docs = array( new Document('1', array('price' => 5)), new Document('2', array('price' => 8)), diff --git a/test/lib/Elastica/Test/Aggregation/BaseAggregationTest.php b/test/lib/Elastica/Test/Aggregation/BaseAggregationTest.php index e7b5734a16..5287e7ba9c 100644 --- a/test/lib/Elastica/Test/Aggregation/BaseAggregationTest.php +++ b/test/lib/Elastica/Test/Aggregation/BaseAggregationTest.php @@ -11,17 +11,4 @@ abstract class BaseAggregationTest extends Base * @var Index */ protected $_index; - - protected function tearDown() - { - parent::tearDown(); - if ($this->_index instanceof Index) { - $this->_index->delete(); - } - } - - protected function _createIndex($name = 'test', $delete = true, $shards = 1) - { - return parent::_createIndex('test_aggregation_'.$name, $delete, $shards); - } } diff --git a/test/lib/Elastica/Test/Aggregation/CardinalityTest.php b/test/lib/Elastica/Test/Aggregation/CardinalityTest.php index c591021451..63c72c60f1 100644 --- a/test/lib/Elastica/Test/Aggregation/CardinalityTest.php +++ b/test/lib/Elastica/Test/Aggregation/CardinalityTest.php @@ -11,7 +11,7 @@ class CardinalityTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex("cardinality"); + $this->_index = $this->_createIndex(); $docs = array( new Document("1", array("color" => "blue")), new Document("2", array("color" => "blue")), diff --git a/test/lib/Elastica/Test/Aggregation/DateHistogramTest.php b/test/lib/Elastica/Test/Aggregation/DateHistogramTest.php index b27cb2f2b6..7a9da93f4a 100644 --- a/test/lib/Elastica/Test/Aggregation/DateHistogramTest.php +++ b/test/lib/Elastica/Test/Aggregation/DateHistogramTest.php @@ -12,7 +12,7 @@ class DateHistogramTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex("date_histogram"); + $this->_index = $this->_createIndex(); $mapping = new Mapping(); $mapping->setProperties(array( "created" => array("type" => "date"), diff --git a/test/lib/Elastica/Test/Aggregation/DateRangeTest.php b/test/lib/Elastica/Test/Aggregation/DateRangeTest.php index 6dcfc60c5b..3926a86f18 100644 --- a/test/lib/Elastica/Test/Aggregation/DateRangeTest.php +++ b/test/lib/Elastica/Test/Aggregation/DateRangeTest.php @@ -12,7 +12,7 @@ class DateRangeTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex("date_range"); + $this->_index = $this->_createIndex(); $mapping = new Mapping(); $mapping->setProperties(array( "created" => array("type" => "date"), diff --git a/test/lib/Elastica/Test/Aggregation/ExtendedStatsTest.php b/test/lib/Elastica/Test/Aggregation/ExtendedStatsTest.php index e7561606c6..6948cd8810 100644 --- a/test/lib/Elastica/Test/Aggregation/ExtendedStatsTest.php +++ b/test/lib/Elastica/Test/Aggregation/ExtendedStatsTest.php @@ -11,7 +11,7 @@ class ExtendedStatsTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex("extended_stats"); + $this->_index = $this->_createIndex(); $docs = array( new Document("1", array("price" => 5)), new Document("2", array("price" => 8)), diff --git a/test/lib/Elastica/Test/Aggregation/FilterTest.php b/test/lib/Elastica/Test/Aggregation/FilterTest.php index f3fca151df..6c16165e05 100644 --- a/test/lib/Elastica/Test/Aggregation/FilterTest.php +++ b/test/lib/Elastica/Test/Aggregation/FilterTest.php @@ -14,7 +14,7 @@ class FilterTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex("filter"); + $this->_index = $this->_createIndex(); $docs = array( new Document("1", array("price" => 5, "color" => "blue")), new Document("2", array("price" => 8, "color" => "blue")), diff --git a/test/lib/Elastica/Test/Aggregation/GeoDistanceTest.php b/test/lib/Elastica/Test/Aggregation/GeoDistanceTest.php index 7dbff9d3ce..d37aeb6089 100644 --- a/test/lib/Elastica/Test/Aggregation/GeoDistanceTest.php +++ b/test/lib/Elastica/Test/Aggregation/GeoDistanceTest.php @@ -12,7 +12,7 @@ class GeoDistanceTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex("geo_distance"); + $this->_index = $this->_createIndex(); $mapping = new Mapping(); $mapping->setProperties(array( "location" => array("type" => "geo_point"), diff --git a/test/lib/Elastica/Test/Aggregation/GeohashGridTest.php b/test/lib/Elastica/Test/Aggregation/GeohashGridTest.php index 95104d53a6..748fb9cf83 100644 --- a/test/lib/Elastica/Test/Aggregation/GeohashGridTest.php +++ b/test/lib/Elastica/Test/Aggregation/GeohashGridTest.php @@ -12,7 +12,7 @@ class GeohashGridTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex("geohash_grid"); + $this->_index = $this->_createIndex(); $mapping = new Mapping(); $mapping->setProperties(array( "location" => array("type" => "geo_point"), diff --git a/test/lib/Elastica/Test/Aggregation/HistogramTest.php b/test/lib/Elastica/Test/Aggregation/HistogramTest.php index 47e15fa744..c27f687ee7 100644 --- a/test/lib/Elastica/Test/Aggregation/HistogramTest.php +++ b/test/lib/Elastica/Test/Aggregation/HistogramTest.php @@ -11,7 +11,7 @@ class HistogramTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex("histogram"); + $this->_index = $this->_createIndex(); $docs = array( new Document("1", array("price" => 5, "color" => "blue")), new Document("2", array("price" => 8, "color" => "blue")), diff --git a/test/lib/Elastica/Test/Aggregation/IpRangeTest.php b/test/lib/Elastica/Test/Aggregation/IpRangeTest.php index 25ebca401d..23c0c72e8b 100644 --- a/test/lib/Elastica/Test/Aggregation/IpRangeTest.php +++ b/test/lib/Elastica/Test/Aggregation/IpRangeTest.php @@ -12,7 +12,7 @@ class IpRangeTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex("ip_range"); + $this->_index = $this->_createIndex(); $mapping = new Mapping(); $mapping->setProperties(array( "address" => array("type" => "ip"), diff --git a/test/lib/Elastica/Test/Aggregation/MaxTest.php b/test/lib/Elastica/Test/Aggregation/MaxTest.php index ebbacf43b0..d28d7c132e 100644 --- a/test/lib/Elastica/Test/Aggregation/MaxTest.php +++ b/test/lib/Elastica/Test/Aggregation/MaxTest.php @@ -12,7 +12,7 @@ class MaxTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex('max'); + $this->_index = $this->_createIndex(); $docs = array( new Document('1', array('price' => 5)), new Document('2', array('price' => 8)), diff --git a/test/lib/Elastica/Test/Aggregation/MinTest.php b/test/lib/Elastica/Test/Aggregation/MinTest.php index c07a83f7fb..30b76fab9d 100644 --- a/test/lib/Elastica/Test/Aggregation/MinTest.php +++ b/test/lib/Elastica/Test/Aggregation/MinTest.php @@ -11,7 +11,7 @@ class MinTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex('min'); + $this->_index = $this->_createIndex(); $docs = array( new Document('1', array('price' => 5)), new Document('2', array('price' => 8)), diff --git a/test/lib/Elastica/Test/Aggregation/MissingTest.php b/test/lib/Elastica/Test/Aggregation/MissingTest.php index 613ba243a9..0b2c57a465 100644 --- a/test/lib/Elastica/Test/Aggregation/MissingTest.php +++ b/test/lib/Elastica/Test/Aggregation/MissingTest.php @@ -11,7 +11,7 @@ class MissingTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex('missing'); + $this->_index = $this->_createIndex(); $docs = array( new Document('1', array('price' => 5, "color" => "blue")), new Document('2', array('price' => 8, "color" => "blue")), diff --git a/test/lib/Elastica/Test/Aggregation/NestedTest.php b/test/lib/Elastica/Test/Aggregation/NestedTest.php index b7a25af7da..779a694b21 100644 --- a/test/lib/Elastica/Test/Aggregation/NestedTest.php +++ b/test/lib/Elastica/Test/Aggregation/NestedTest.php @@ -13,7 +13,7 @@ class NestedTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex("nested"); + $this->_index = $this->_createIndex(); $mapping = new Mapping(); $mapping->setProperties(array( "resellers" => array( diff --git a/test/lib/Elastica/Test/Aggregation/RangeTest.php b/test/lib/Elastica/Test/Aggregation/RangeTest.php index 02dcb51065..521a6a05c4 100644 --- a/test/lib/Elastica/Test/Aggregation/RangeTest.php +++ b/test/lib/Elastica/Test/Aggregation/RangeTest.php @@ -11,7 +11,7 @@ class RangeTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex('range'); + $this->_index = $this->_createIndex(); $docs = array( new Document('1', array('price' => 5)), new Document('2', array('price' => 8)), diff --git a/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php b/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php index 0649e6b185..fead9abcad 100644 --- a/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php +++ b/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php @@ -14,7 +14,7 @@ class ReverseNestedTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex("nested"); + $this->_index = $this->_createIndex(); $mapping = new Mapping(); $mapping->setProperties(array( "comments" => array( diff --git a/test/lib/Elastica/Test/Aggregation/ScriptTest.php b/test/lib/Elastica/Test/Aggregation/ScriptTest.php index 912dddd085..9fe75ce4ce 100644 --- a/test/lib/Elastica/Test/Aggregation/ScriptTest.php +++ b/test/lib/Elastica/Test/Aggregation/ScriptTest.php @@ -12,7 +12,7 @@ class ScriptTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex('script'); + $this->_index = $this->_createIndex(); $docs = array( new Document('1', array('price' => 5)), new Document('2', array('price' => 8)), diff --git a/test/lib/Elastica/Test/Aggregation/StatsTest.php b/test/lib/Elastica/Test/Aggregation/StatsTest.php index 9add17e41a..7f7a755ec2 100644 --- a/test/lib/Elastica/Test/Aggregation/StatsTest.php +++ b/test/lib/Elastica/Test/Aggregation/StatsTest.php @@ -11,7 +11,7 @@ class StatsTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex('stats'); + $this->_index = $this->_createIndex(); $docs = array( new Document('1', array('price' => 5)), new Document('2', array('price' => 8)), diff --git a/test/lib/Elastica/Test/Aggregation/SumTest.php b/test/lib/Elastica/Test/Aggregation/SumTest.php index b94e6f775d..b2cb4e7bcc 100644 --- a/test/lib/Elastica/Test/Aggregation/SumTest.php +++ b/test/lib/Elastica/Test/Aggregation/SumTest.php @@ -11,7 +11,7 @@ class SumTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex('sum'); + $this->_index = $this->_createIndex(); $docs = array( new Document('1', array('price' => 5)), new Document('2', array('price' => 8)), diff --git a/test/lib/Elastica/Test/Aggregation/TermsTest.php b/test/lib/Elastica/Test/Aggregation/TermsTest.php index b5eee91264..b10d4ead64 100644 --- a/test/lib/Elastica/Test/Aggregation/TermsTest.php +++ b/test/lib/Elastica/Test/Aggregation/TermsTest.php @@ -11,7 +11,7 @@ class TermsTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex("terms"); + $this->_index = $this->_createIndex(); $docs = array( new Document("1", array("color" => "blue")), new Document("2", array("color" => "blue")), diff --git a/test/lib/Elastica/Test/Aggregation/TopHitsTest.php b/test/lib/Elastica/Test/Aggregation/TopHitsTest.php index 87a5eb01c4..992004516d 100644 --- a/test/lib/Elastica/Test/Aggregation/TopHitsTest.php +++ b/test/lib/Elastica/Test/Aggregation/TopHitsTest.php @@ -18,7 +18,7 @@ class TopHitsTest extends BaseAggregationTest public function setUp() { parent::setUp(); - $this->_index = $this->_createIndex('top_hits_test', true); + $this->_index = $this->_createIndex(); $docs = array( new Document(1, array( diff --git a/test/lib/Elastica/Test/Aggregation/ValueCountTest.php b/test/lib/Elastica/Test/Aggregation/ValueCountTest.php index 01f0e855c6..5a01eff110 100644 --- a/test/lib/Elastica/Test/Aggregation/ValueCountTest.php +++ b/test/lib/Elastica/Test/Aggregation/ValueCountTest.php @@ -11,7 +11,7 @@ class ValueCountTest extends BaseAggregationTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex('value_count'); + $this->_index = $this->_createIndex(); $docs = array( new Document('1', array('price' => 5)), new Document('2', array('price' => 8)), diff --git a/test/lib/Elastica/Test/Base.php b/test/lib/Elastica/Test/Base.php index 6376d6e2cd..85480d14fd 100644 --- a/test/lib/Elastica/Test/Base.php +++ b/test/lib/Elastica/Test/Base.php @@ -21,8 +21,12 @@ protected function _getClient() * @param int $shards Number of shards to create * @return \Elastica\Index */ - protected function _createIndex($name = 'test', $delete = true, $shards = 1) + protected function _createIndex($name = null, $delete = true, $shards = 1) { + if (is_null($name)) { + $name = preg_replace('/[^a-z]/i', '', strtolower(get_called_class())).uniqid(); + } + $client = $this->_getClient(); $index = $client->getIndex('elastica_'.$name); $index->create(array('index' => array('number_of_shards' => $shards, 'number_of_replicas' => 0)), $delete); @@ -42,4 +46,10 @@ protected function _waitForAllocation(Index $index) } } while (!$allocated); } + + protected function tearDown() + { + $this->_getClient()->getIndex('_all')->delete(); + $this->_getClient()->getIndex('_all')->clearCache(); + } } diff --git a/test/lib/Elastica/Test/BulkTest.php b/test/lib/Elastica/Test/BulkTest.php index 7a27ba8a1c..4f0034221b 100644 --- a/test/lib/Elastica/Test/BulkTest.php +++ b/test/lib/Elastica/Test/BulkTest.php @@ -19,6 +19,7 @@ class BulkTest extends BaseTest public function testSend() { $index = $this->_createIndex(); + $indexName = $index->getName(); $type = $index->getType('bulk_test'); $type2 = $index->getType('bulk_test2'); $client = $index->getClient(); @@ -63,24 +64,24 @@ public function testSend() $data = $bulk->toArray(); $expected = array( - array('index' => array('_index' => 'elastica_test', '_type' => 'bulk_test', '_id' => 1, '_percolate' => '*')), + array('index' => array('_index' => $indexName, '_type' => 'bulk_test', '_id' => 1, '_percolate' => '*')), array('name' => 'Mister Fantastic'), array('index' => array('_id' => 2)), array('name' => 'Invisible Woman'), - array('create' => array('_index' => 'elastica_test', '_type' => 'bulk_test', '_id' => 3)), + array('create' => array('_index' => $indexName, '_type' => 'bulk_test', '_id' => 3)), array('name' => 'The Human Torch'), - array('index' => array('_index' => 'elastica_test', '_type' => 'bulk_test')), + array('index' => array('_index' => $indexName, '_type' => 'bulk_test')), array('name' => 'The Thing'), ); $this->assertEquals($expected, $data); - $expected = '{"index":{"_index":"elastica_test","_type":"bulk_test","_id":1,"_percolate":"*"}} + $expected = '{"index":{"_index":"'.$indexName.'","_type":"bulk_test","_id":1,"_percolate":"*"}} {"name":"Mister Fantastic"} {"index":{"_id":2}} {"name":"Invisible Woman"} -{"create":{"_index":"elastica_test","_type":"bulk_test","_id":3}} +{"create":{"_index":"'.$indexName.'","_type":"bulk_test","_id":3}} {"name":"The Human Torch"} -{"index":{"_index":"elastica_test","_type":"bulk_test"}} +{"index":{"_index":"'.$indexName.'","_type":"bulk_test"}} {"name":"The Thing"} '; @@ -113,7 +114,7 @@ public function testSend() $data = $bulk->toArray(); $expected = array( - array('delete' => array('_index' => 'elastica_test', '_type' => 'bulk_test', '_id' => 3)), + array('delete' => array('_index' => $indexName, '_type' => 'bulk_test', '_id' => 3)), ); $this->assertEquals($expected, $data); diff --git a/test/lib/Elastica/Test/ClientTest.php b/test/lib/Elastica/Test/ClientTest.php index 26b49a9ebd..87e2f3cbbd 100644 --- a/test/lib/Elastica/Test/ClientTest.php +++ b/test/lib/Elastica/Test/ClientTest.php @@ -262,7 +262,7 @@ public function testDeleteIdsIdxStringTypeString() $data = array('username' => 'hans'); $userSearch = 'username:hans'; - $index = $this->_createIndex('test', true, 2); + $index = $this->_createIndex(null, true, 2); // Create the index, deleting it first if it already exists $index->create(array(), true); diff --git a/test/lib/Elastica/Test/Cluster/SettingsTest.php b/test/lib/Elastica/Test/Cluster/SettingsTest.php index 97329b31f3..1ba655d2a7 100644 --- a/test/lib/Elastica/Test/Cluster/SettingsTest.php +++ b/test/lib/Elastica/Test/Cluster/SettingsTest.php @@ -52,8 +52,8 @@ public function testSetReadOnly() // Create two indices to check that the complete cluster is read only $settings = new Settings($this->_getClient()); $settings->setReadOnly(false); - $index1 = $this->_createIndex('test1'); - $index2 = $this->_createIndex('test2'); + $index1 = $this->_createIndex(); + $index2 = $this->_createIndex(); $doc1 = new Document(null, array('hello' => 'world')); $doc2 = new Document(null, array('hello' => 'world')); diff --git a/test/lib/Elastica/Test/ClusterTest.php b/test/lib/Elastica/Test/ClusterTest.php index 87a7508db9..a8efc3cd6a 100644 --- a/test/lib/Elastica/Test/ClusterTest.php +++ b/test/lib/Elastica/Test/ClusterTest.php @@ -47,8 +47,7 @@ public function testGetIndexNames() $client = $this->_getClient(); $cluster = $client->getCluster(); - $indexName = 'elastica_test999'; - $index = $this->_createIndex($indexName); + $index = $this->_createIndex(); $index->delete(); $cluster->refresh(); @@ -56,7 +55,7 @@ public function testGetIndexNames() $indexNames = $cluster->getIndexNames(); $this->assertNotContains($index->getName(), $indexNames); - $index = $this->_createIndex($indexName); + $index = $this->_createIndex(); $cluster->refresh(); // Now index should exist diff --git a/test/lib/Elastica/Test/Exception/ResponseExceptionTest.php b/test/lib/Elastica/Test/Exception/ResponseExceptionTest.php index 2f7eb2a11e..6829aa9119 100644 --- a/test/lib/Elastica/Test/Exception/ResponseExceptionTest.php +++ b/test/lib/Elastica/Test/Exception/ResponseExceptionTest.php @@ -31,7 +31,7 @@ public function testCreateExistingIndex() public function testBadType() { - $index = $this->_createIndex('woo'); + $index = $this->_createIndex(); $type = $index->getType('test'); $type->setMapping(array( @@ -53,7 +53,7 @@ public function testBadType() public function testWhatever() { - $index = $this->_createIndex('woo'); + $index = $this->_createIndex(); $index->delete(); try { diff --git a/test/lib/Elastica/Test/Facet/GeoClusterTest.php b/test/lib/Elastica/Test/Facet/GeoClusterTest.php index 125c1db6be..d2c89f821e 100644 --- a/test/lib/Elastica/Test/Facet/GeoClusterTest.php +++ b/test/lib/Elastica/Test/Facet/GeoClusterTest.php @@ -18,7 +18,7 @@ public function testQuery() $this->markTestSkipped('geocluster-facet plugin not installed'); } - $index = $this->_createIndex('geocluster_test'); + $index = $this->_createIndex(); $type = $index->getType('testQuery'); $geoField = 'location'; diff --git a/test/lib/Elastica/Test/Filter/BoolTest.php b/test/lib/Elastica/Test/Filter/BoolTest.php index 4b61bc097e..4dc1b66340 100644 --- a/test/lib/Elastica/Test/Filter/BoolTest.php +++ b/test/lib/Elastica/Test/Filter/BoolTest.php @@ -92,7 +92,7 @@ public function testToArray(Bool $bool, $expectedArray) public function testBoolFilter() { - $index = $this->_createIndex('bool_filter_test'); + $index = $this->_createIndex(); $type = $index->getType('book'); //index some test data diff --git a/test/lib/Elastica/Test/Filter/GeoDistanceTest.php b/test/lib/Elastica/Test/Filter/GeoDistanceTest.php index d8ba24645d..ac4ecc9dc0 100644 --- a/test/lib/Elastica/Test/Filter/GeoDistanceTest.php +++ b/test/lib/Elastica/Test/Filter/GeoDistanceTest.php @@ -12,9 +12,7 @@ class GeoDistanceTest extends BaseTest { public function testGeoPoint() { - $client = $this->_getClient(); - $index = $client->getIndex('test'); - $index->create(array(), true); + $index = $this->_createIndex(); $type = $index->getType('test'); diff --git a/test/lib/Elastica/Test/Filter/GeoPolygonTest.php b/test/lib/Elastica/Test/Filter/GeoPolygonTest.php index 607aef4664..c591f83180 100644 --- a/test/lib/Elastica/Test/Filter/GeoPolygonTest.php +++ b/test/lib/Elastica/Test/Filter/GeoPolygonTest.php @@ -12,9 +12,7 @@ class GeoPolygonTest extends BaseTest { public function testGeoPoint() { - $client = $this->_getClient(); - $index = $client->getIndex('test'); - $index->create(array(), true); + $index = $this->_createIndex(); $type = $index->getType('test'); diff --git a/test/lib/Elastica/Test/Filter/GeoShapePreIndexedTest.php b/test/lib/Elastica/Test/Filter/GeoShapePreIndexedTest.php index d817fa4a9e..a6b6baa540 100644 --- a/test/lib/Elastica/Test/Filter/GeoShapePreIndexedTest.php +++ b/test/lib/Elastica/Test/Filter/GeoShapePreIndexedTest.php @@ -13,8 +13,8 @@ class GeoShapePreIndexedTest extends BaseTest { public function testGeoProvided() { - $indexName = 'geo_shape_filter_test'; - $index = $this->_createIndex($indexName); + $index = $this->_createIndex(); + $indexName = $index->getName(); $type = $index->getType('type'); $otherType = $index->getType('other_type'); @@ -60,7 +60,7 @@ public function testGeoProvided() $index->refresh(); $gsp = new GeoShapePreIndexed( - 'location', '1', 'type', 'elastica_'.$indexName, 'location' + 'location', '1', 'type', $indexName, 'location' ); $gsp->setRelation(AbstractGeoShape::RELATION_INTERSECT); @@ -70,7 +70,7 @@ public function testGeoProvided() 'indexed_shape' => array( 'id' => '1', 'type' => 'type', - 'index' => 'elastica_'.$indexName, + 'index' => $indexName, 'path' => 'location', ), 'relation' => $gsp->getRelation(), diff --git a/test/lib/Elastica/Test/Filter/GeoShapeProvidedTest.php b/test/lib/Elastica/Test/Filter/GeoShapeProvidedTest.php index baae3260d7..41f4858b0d 100644 --- a/test/lib/Elastica/Test/Filter/GeoShapeProvidedTest.php +++ b/test/lib/Elastica/Test/Filter/GeoShapeProvidedTest.php @@ -13,7 +13,7 @@ class GeoShapeProvidedTest extends BaseTest { public function testConstructEnvelope() { - $index = $this->_createIndex('geo_shape_filter_test'); + $index = $this->_createIndex(); $type = $index->getType('test'); // create mapping @@ -62,8 +62,6 @@ public function testConstructEnvelope() $results = $type->search($query); $this->assertEquals(1, $results->count()); - - $index->delete(); } public function testConstructPolygon() diff --git a/test/lib/Elastica/Test/Filter/GeohashCellTest.php b/test/lib/Elastica/Test/Filter/GeohashCellTest.php index 2f637a81a8..d2c3783748 100644 --- a/test/lib/Elastica/Test/Filter/GeohashCellTest.php +++ b/test/lib/Elastica/Test/Filter/GeohashCellTest.php @@ -25,7 +25,7 @@ public function testToArray() public function testFilter() { - $index = $this->_createIndex('geohash_filter_test'); + $index = $this->_createIndex(); $type = $index->getType('test'); $mapping = new \Elastica\Type\Mapping($type, array( 'pin' => array( diff --git a/test/lib/Elastica/Test/Filter/IdsTest.php b/test/lib/Elastica/Test/Filter/IdsTest.php index b41a174465..07a4fbdbfb 100644 --- a/test/lib/Elastica/Test/Filter/IdsTest.php +++ b/test/lib/Elastica/Test/Filter/IdsTest.php @@ -15,9 +15,7 @@ class IdsTest extends BaseTest public function setUp() { - $client = $this->_getClient(); - $index = $client->getIndex('test'); - $index->create(array(), true); + $index = $this->_createIndex(); $type1 = $index->getType('helloworld1'); $type2 = $index->getType('helloworld2'); @@ -45,13 +43,6 @@ public function setUp() $this->_index = $index; } - public function tearDown() - { - $client = $this->_getClient(); - $index = $client->getIndex('test'); - $index->delete(); - } - public function testSetIdsSearchSingle() { $filter = new Ids(); diff --git a/test/lib/Elastica/Test/Filter/IndicesTest.php b/test/lib/Elastica/Test/Filter/IndicesTest.php index 4cb99fe0bb..7f0fb65632 100644 --- a/test/lib/Elastica/Test/Filter/IndicesTest.php +++ b/test/lib/Elastica/Test/Filter/IndicesTest.php @@ -25,8 +25,8 @@ class IndicesTest extends BaseTest protected function setUp() { parent::setUp(); - $this->_index1 = $this->_createIndex('indices_filter_1'); - $this->_index2 = $this->_createIndex('indices_filter_2'); + $this->_index1 = $this->_createIndex(); + $this->_index2 = $this->_createIndex(); $this->_index1->addAlias("indices_filter"); $this->_index2->addAlias("indices_filter"); $docs = array( @@ -41,13 +41,6 @@ protected function setUp() $this->_index2->refresh(); } - protected function tearDown() - { - $this->_index1->delete(); - $this->_index2->delete(); - parent::tearDown(); - } - public function testToArray() { $expected = array( diff --git a/test/lib/Elastica/Test/Filter/NestedFilterWithSetFilterTest.php b/test/lib/Elastica/Test/Filter/NestedFilterWithSetFilterTest.php index 498e435213..7a263e0d71 100644 --- a/test/lib/Elastica/Test/Filter/NestedFilterWithSetFilterTest.php +++ b/test/lib/Elastica/Test/Filter/NestedFilterWithSetFilterTest.php @@ -59,13 +59,6 @@ public function setUp() $index->refresh(); } - public function tearDown() - { - $client = $this->_getClient(); - $index = $client->getIndex('elastica_test_filter_nested_abstract_filter'); - $index->delete(); - } - public function testToArray() { $f = new Nested(); diff --git a/test/lib/Elastica/Test/Filter/NestedTest.php b/test/lib/Elastica/Test/Filter/NestedTest.php index 6ecb10fc2c..e23284657f 100644 --- a/test/lib/Elastica/Test/Filter/NestedTest.php +++ b/test/lib/Elastica/Test/Filter/NestedTest.php @@ -59,13 +59,6 @@ public function setUp() $index->refresh(); } - public function tearDown() - { - $client = $this->_getClient(); - $index = $client->getIndex('elastica_test_filter_nested'); - $index->delete(); - } - public function testToArray() { $f = new Nested(); diff --git a/test/lib/Elastica/Test/Filter/PrefixTest.php b/test/lib/Elastica/Test/Filter/PrefixTest.php index 355309b7a4..95bda9e779 100644 --- a/test/lib/Elastica/Test/Filter/PrefixTest.php +++ b/test/lib/Elastica/Test/Filter/PrefixTest.php @@ -30,18 +30,6 @@ public function testDifferentPrefixes() $client = $this->_getClient(); $index = $client->getIndex('test'); - /*$indexParams = array( - 'analysis' => array( - 'analyzer' => array( - 'lw' => array( - 'type' => 'custom', - 'tokenizer' => 'keyword', - 'filter' => array('lowercase') - ) - ), - ) - );*/ - $index->create(array(), true); $type = $index->getType('test'); diff --git a/test/lib/Elastica/Test/Filter/TermsTest.php b/test/lib/Elastica/Test/Filter/TermsTest.php index 70d7e7aeb7..5bc770e13c 100644 --- a/test/lib/Elastica/Test/Filter/TermsTest.php +++ b/test/lib/Elastica/Test/Filter/TermsTest.php @@ -10,7 +10,7 @@ class TermsTest extends BaseTest public function testLookup() { - $index = $this->_createIndex('terms_filter_test'); + $index = $this->_createIndex(); $type1 = $index->getType('musicians'); $type2 = $index->getType('bands'); diff --git a/test/lib/Elastica/Test/Index/SettingsTest.php b/test/lib/Elastica/Test/Index/SettingsTest.php index 10d3ede778..8cd69ca114 100644 --- a/test/lib/Elastica/Test/Index/SettingsTest.php +++ b/test/lib/Elastica/Test/Index/SettingsTest.php @@ -184,7 +184,7 @@ public function testSetMergePolicyType() public function testSetReadOnly() { - $index = $this->_createIndex('test'.rand()); + $index = $this->_createIndex(); //wait for the shards to be allocated $this->_waitForAllocation($index); $index->getSettings()->setReadOnly(false); @@ -225,7 +225,7 @@ public function testSetReadOnly() public function testGetSetBlocksRead() { - $index = $this->_createIndex('elastica-test'.'123'); + $index = $this->_createIndex(); $index->refresh(); $settings = $index->getSettings(); @@ -245,7 +245,7 @@ public function testGetSetBlocksRead() public function testGetSetBlocksWrite() { - $index = $this->_createIndex('elastica-test'.'432'); + $index = $this->_createIndex(); $index->refresh(); $settings = $index->getSettings(); @@ -265,7 +265,7 @@ public function testGetSetBlocksWrite() public function testGetSetBlocksMetadata() { - $index = $this->_createIndex('elastica-test'.'534'); + $index = $this->_createIndex(); $index->refresh(); $settings = $index->getSettings(); diff --git a/test/lib/Elastica/Test/IndexTest.php b/test/lib/Elastica/Test/IndexTest.php index 728d39c6db..ce0a5bcdbc 100644 --- a/test/lib/Elastica/Test/IndexTest.php +++ b/test/lib/Elastica/Test/IndexTest.php @@ -43,11 +43,10 @@ public function testMapping() public function testGetMappingAlias() { - $indexName = 'test-mapping'; - $aliasName = 'test-mapping-alias'; - - $index = $this->_createIndex($indexName); + $index = $this->_createIndex(); $indexName = $index->getName(); + + $aliasName = 'test-mapping-alias'; $index->addAlias($aliasName); $type = new Type($index, 'test'); @@ -430,18 +429,14 @@ public function testAddDocumentVersion() public function testClearCache() { - $client = $this->_getClient(); - $index1 = $client->getIndex('test1'); - - $response = $index1->clearCache(); + $index = $this->_createIndex(); + $response = $index->clearCache(); $this->assertFalse($response->hasError()); } public function testFlush() { - $client = $this->_getClient(); - $index = $client->getIndex('test1'); - + $index = $this->_createIndex(); $response = $index->flush(); $this->assertFalse($response->hasError()); } @@ -668,7 +663,7 @@ public function testOptimize() public function testAnalyze() { - $index = $this->_createIndex('analyze'); + $index = $this->_createIndex(); $index->optimize(); sleep(2); $returnedTokens = $index->analyze('foo'); diff --git a/test/lib/Elastica/Test/NodeTest.php b/test/lib/Elastica/Test/NodeTest.php index 4e28a4ca7c..93727679a7 100644 --- a/test/lib/Elastica/Test/NodeTest.php +++ b/test/lib/Elastica/Test/NodeTest.php @@ -48,9 +48,9 @@ public function testGetStats() public function testGetName() { $nodes = $this->_getClient()->getCluster()->getNodes(); - $this->assertCount(3, $nodes); + $this->assertCount(2, $nodes); foreach ($nodes as $node) { - $this->assertContains($node->getName(), ['Silver Fox', 'Skywalker', 'Wolverine']); + $this->assertContains($node->getName(), ['Silver Fox', 'Skywalker']); } } } diff --git a/test/lib/Elastica/Test/PercolatorTest.php b/test/lib/Elastica/Test/PercolatorTest.php index 677929df73..9184c6cb3e 100644 --- a/test/lib/Elastica/Test/PercolatorTest.php +++ b/test/lib/Elastica/Test/PercolatorTest.php @@ -14,9 +14,8 @@ class PercolatorTest extends BaseTest { public function testConstruct() { - $percolatorName = 'percotest'; - - $index = $this->_createIndex($percolatorName); + $index = $this->_createIndex(); + $percolatorName = $index->getName(); $percolator = new Percolator($index); @@ -44,7 +43,7 @@ public function testMatchDoc() $percolator = new Percolator($index); - $percolatorName = 'percotest'; + $percolatorName = $index->getName(); $query = new Term(array('name' => 'ruflin')); $response = $percolator->registerQuery($percolatorName, $query); @@ -285,7 +284,7 @@ public function testPercolateExistingDocWithAdditionalRequestBodyOptions() $index->delete(); } - protected function _createIndex($name = 'test', $delete = true, $shards = 1) + protected function _createIndex($name = null, $delete = true, $shards = 1) { $index = parent::_createIndex($name, $delete, $shards); $type = $index->getType('.percolator'); diff --git a/test/lib/Elastica/Test/Query/BoostingTest.php b/test/lib/Elastica/Test/Query/BoostingTest.php index 6644cee18e..d2126b207c 100644 --- a/test/lib/Elastica/Test/Query/BoostingTest.php +++ b/test/lib/Elastica/Test/Query/BoostingTest.php @@ -26,7 +26,7 @@ class BoostingTest extends BaseTest protected function setUp() { parent::setUp(); - $this->index = $this->_createIndex('test_boostingquery'); + $this->index = $this->_createIndex(); $this->type = $this->index->getType('test'); $this->type->setMapping(array( 'name' => array('type' => 'string', 'index' => 'analyzed'), @@ -48,12 +48,6 @@ protected function setUp() $this->index->refresh(); } - protected function tearDown() - { - $this->index->delete(); - parent::tearDown(); - } - public function testToArray() { $keyword = "vital"; diff --git a/test/lib/Elastica/Test/Query/BuilderTest.php b/test/lib/Elastica/Test/Query/BuilderTest.php index 79a7cac2e2..670301661a 100644 --- a/test/lib/Elastica/Test/Query/BuilderTest.php +++ b/test/lib/Elastica/Test/Query/BuilderTest.php @@ -20,6 +20,7 @@ public function setUp() public function tearDown() { $this->builder = null; + parent::tearDown(); } /** diff --git a/test/lib/Elastica/Test/Query/CommonTest.php b/test/lib/Elastica/Test/Query/CommonTest.php index 84b66f7d72..31389e9ed6 100644 --- a/test/lib/Elastica/Test/Query/CommonTest.php +++ b/test/lib/Elastica/Test/Query/CommonTest.php @@ -27,7 +27,7 @@ public function testToArray() public function testQuery() { - $index = $this->_createIndex('common_test'); + $index = $this->_createIndex(); $type = $index->getType('test'); //add documents to create common terms diff --git a/test/lib/Elastica/Test/Query/FunctionScoreTest.php b/test/lib/Elastica/Test/Query/FunctionScoreTest.php index faaa828ca9..5466b0d3e3 100644 --- a/test/lib/Elastica/Test/Query/FunctionScoreTest.php +++ b/test/lib/Elastica/Test/Query/FunctionScoreTest.php @@ -29,7 +29,7 @@ class FunctionScoreTest extends BaseTest protected function setUp() { parent::setUp(); - $this->index = $this->_createIndex('test_functionscore'); + $this->index = $this->_createIndex(); $this->type = $this->index->getType('test'); $this->type->setMapping(array( 'name' => array('type' => 'string', 'index' => 'not_analyzed'), @@ -51,12 +51,6 @@ protected function setUp() $this->index->refresh(); } - protected function tearDown() - { - $this->index->delete(); - parent::tearDown(); - } - public function testToArray() { $priceOrigin = 0; diff --git a/test/lib/Elastica/Test/Query/IdsTest.php b/test/lib/Elastica/Test/Query/IdsTest.php index d1bf901e58..93320a926c 100644 --- a/test/lib/Elastica/Test/Query/IdsTest.php +++ b/test/lib/Elastica/Test/Query/IdsTest.php @@ -38,13 +38,6 @@ public function setUp() $this->_index = $index; } - public function tearDown() - { - $client = $this->_getClient(); - $index = $client->getIndex('test'); - $index->delete(); - } - public function testSetIdsSearchSingle() { $query = new Ids(); diff --git a/test/lib/Elastica/Test/Query/MatchAllTest.php b/test/lib/Elastica/Test/Query/MatchAllTest.php index 3731e6597b..fa3cc677a4 100644 --- a/test/lib/Elastica/Test/Query/MatchAllTest.php +++ b/test/lib/Elastica/Test/Query/MatchAllTest.php @@ -20,8 +20,8 @@ public function testToArray() public function testMatchAllIndicesTypes() { - $index1 = $this->_createIndex('test1'); - $index2 = $this->_createIndex('test2'); + $index1 = $this->_createIndex(); + $index2 = $this->_createIndex(); $client = $index1->getClient(); diff --git a/test/lib/Elastica/Test/Query/PostFilterTest.php b/test/lib/Elastica/Test/Query/PostFilterTest.php index 690d4ee79e..53e6b2eb6a 100644 --- a/test/lib/Elastica/Test/Query/PostFilterTest.php +++ b/test/lib/Elastica/Test/Query/PostFilterTest.php @@ -19,7 +19,7 @@ class PostFilterTest extends BaseTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex("query"); + $this->_index = $this->_createIndex(); $docs = array( new Document("1", array("color" => "green", "make" => "ford")), new Document("2", array("color" => "blue", "make" => "volvo")), @@ -30,14 +30,6 @@ protected function setUp() $this->_index->refresh(); } - protected function tearDown() - { - parent::tearDown(); - if ($this->_index instanceof Index) { - $this->_index->delete(); - } - } - public function testToArray() { $query = new Query(); @@ -69,9 +61,4 @@ public function testQuery() $this->assertEquals(1, $results->getTotalHits()); } - - protected function _createIndex($name = 'test', $delete = true, $shards = 1) - { - return parent::_createIndex('test_postfilter_'.$name, $delete, $shards); - } } diff --git a/test/lib/Elastica/Test/Query/RescoreTest.php b/test/lib/Elastica/Test/Query/RescoreTest.php index 16ef05edd3..34007d95ad 100644 --- a/test/lib/Elastica/Test/Query/RescoreTest.php +++ b/test/lib/Elastica/Test/Query/RescoreTest.php @@ -18,7 +18,7 @@ class RescoreTest extends BaseTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex("rescore_test"); + $this->_index = $this->_createIndex(); $this->_index->refresh(); } diff --git a/test/lib/Elastica/Test/Query/SimpleQueryStringTest.php b/test/lib/Elastica/Test/Query/SimpleQueryStringTest.php index 85da04338e..366bb32ca0 100644 --- a/test/lib/Elastica/Test/Query/SimpleQueryStringTest.php +++ b/test/lib/Elastica/Test/Query/SimpleQueryStringTest.php @@ -17,7 +17,7 @@ class SimpleQueryStringTest extends Base protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex("simple_query_string_test"); + $this->_index = $this->_createIndex(); $docs = array( new Document(1, array('make' => 'Gibson', 'model' => 'Les Paul')), new Document(2, array('make' => 'Gibson', 'model' => 'SG Standard')), @@ -29,12 +29,6 @@ protected function setUp() $this->_index->refresh(); } - protected function tearDown() - { - parent::tearDown(); - $this->_index->delete(); - } - public function testToArray() { $string = "this is a test"; diff --git a/test/lib/Elastica/Test/ScanAndScrollTest.php b/test/lib/Elastica/Test/ScanAndScrollTest.php index 3fda0ae9c4..3a52265aa6 100644 --- a/test/lib/Elastica/Test/ScanAndScrollTest.php +++ b/test/lib/Elastica/Test/ScanAndScrollTest.php @@ -32,7 +32,7 @@ public function testQuerySizeOverride() $query = new Query(); $query->setSize(100); - $index = $this->_createIndex('test_1'); + $index = $this->_createIndex(); $index->refresh(); // Waits for the index to be fully created. $type = $index->getType('scanAndScrollTest'); @@ -49,7 +49,7 @@ public function testQuerySizeOverride() public function testSizePerShard() { - $search = $this->_prepareSearch('test_2', 2, 20); + $search = $this->_prepareSearch(2, 20); $scanAndScroll = new ScanAndScroll($search); $scanAndScroll->sizePerShard = 5; @@ -60,7 +60,7 @@ public function testSizePerShard() public function testScrollId() { - $search = $this->_prepareSearch('test_3', 1, 2); + $search = $this->_prepareSearch(1, 2); $scanAndScroll = new ScanAndScroll($search); $scanAndScroll->sizePerShard = 1; @@ -74,7 +74,7 @@ public function testScrollId() public function testForeach() { - $search = $this->_prepareSearch('test_4', 2, 11); + $search = $this->_prepareSearch(2, 11); $scanAndScroll = new ScanAndScroll($search); $scanAndScroll->sizePerShard = 5; @@ -103,9 +103,9 @@ private function _prepareScanAndScroll() return new ScanAndScroll(new Search($this->_getClient())); } - private function _prepareSearch($indexName, $indexShards, $docs) + private function _prepareSearch($indexShards, $docs) { - $index = $this->_createIndex($indexName, true, $indexShards); + $index = $this->_createIndex(null, true, $indexShards); $type = $index->getType('scanAndScrollTest'); $insert = array(); diff --git a/test/lib/Elastica/Test/ScriptFieldsTest.php b/test/lib/Elastica/Test/ScriptFieldsTest.php index 6dc844773f..e1dfc13c53 100644 --- a/test/lib/Elastica/Test/ScriptFieldsTest.php +++ b/test/lib/Elastica/Test/ScriptFieldsTest.php @@ -17,12 +17,6 @@ public function setUp() $this->index = $this->_createIndex(); } - protected function tearDown() - { - $this->index->delete(); - parent::tearDown(); - } - public function testNewScriptFields() { $script = new Script('1 + 2'); diff --git a/test/lib/Elastica/Test/SearchTest.php b/test/lib/Elastica/Test/SearchTest.php index 35487c58f2..8e2bef8aa2 100644 --- a/test/lib/Elastica/Test/SearchTest.php +++ b/test/lib/Elastica/Test/SearchTest.php @@ -31,8 +31,8 @@ public function testAddIndex() $client = $this->_getClient(); $search = new Search($client); - $index1 = $this->_createIndex('test1'); - $index2 = $this->_createIndex('test2'); + $index1 = $this->_createIndex(); + $index2 = $this->_createIndex(); $search->addIndex($index1); $indices = $search->getIndices(); @@ -156,8 +156,8 @@ public function testGetPath() $search1 = new Search($client); $search2 = new Search($client); - $index1 = $this->_createIndex('test1'); - $index2 = $this->_createIndex('test2'); + $index1 = $this->_createIndex(); + $index2 = $this->_createIndex(); $type1 = $index1->getType('type1'); $type2 = $index1->getType('type2'); @@ -191,8 +191,8 @@ public function testSearchRequest() $client = $this->_getClient(); $search1 = new Search($client); - $index1 = $this->_createIndex('test1'); - $index2 = $this->_createIndex('test2'); + $index1 = $this->_createIndex(); + $index2 = $this->_createIndex(); $type1 = $index1->getType('hello1'); @@ -219,7 +219,7 @@ public function testSearchScrollRequest() { $client = $this->_getClient(); - $index = $this->_createIndex('test'); + $index = $this->_createIndex(); $type = $index->getType('scrolltest'); $docs = array(); @@ -386,7 +386,7 @@ public function testArrayConfigSearch() public function testSearchWithVersionOption() { - $index = $this->_createIndex('test1'); + $index = $this->_createIndex(); $doc = new Document(1, array('id' => 1, 'email' => 'test@test.com', 'username' => 'ruflin')); $index->getType('test')->addDocument($doc); $index->refresh(); @@ -490,7 +490,7 @@ public function testEmptySearch() public function testCount() { - $index = $this->_createIndex('eeee'); + $index = $this->_createIndex(); $search = new Search($index->getClient()); $type = $index->getType('test'); diff --git a/test/lib/Elastica/Test/SnapshotTest.php b/test/lib/Elastica/Test/SnapshotTest.php index c7036a0b48..f650d749d7 100644 --- a/test/lib/Elastica/Test/SnapshotTest.php +++ b/test/lib/Elastica/Test/SnapshotTest.php @@ -28,7 +28,7 @@ protected function setUp() parent::setUp(); $this->_snapshot = new Snapshot($this->_getClient()); - $this->_index = $this->_createIndex("test_snapshot"); + $this->_index = $this->_createIndex(); $this->_docs = array( new Document("1", array("city" => "San Diego")), new Document("2", array("city" => "San Luis Obispo")), @@ -38,12 +38,6 @@ protected function setUp() $this->_index->refresh(); } - protected function tearDown() - { - parent::tearDown(); - $this->_index->delete(); - } - public function testRegisterRepository() { $name = "test_register"; diff --git a/test/lib/Elastica/Test/StatusTest.php b/test/lib/Elastica/Test/StatusTest.php index 7f23c22688..ccf289af2e 100644 --- a/test/lib/Elastica/Test/StatusTest.php +++ b/test/lib/Elastica/Test/StatusTest.php @@ -75,10 +75,10 @@ public function testIndexExists() public function testAliasExists() { - $indexName = 'test'; $aliasName = 'elastica_test-alias'; $index1 = $this->_createIndex(); + $indexName = $index1->getName(); $status = new Status($index1->getClient()); @@ -93,7 +93,7 @@ public function testAliasExists() $this->assertTrue($status->aliasExists($aliasName)); $indicesWithAlias = $status->getIndicesWithAlias($aliasName); - $this->assertEquals(array("elastica_$indexName"), array_map( + $this->assertEquals(array($indexName), array_map( function ($index) { return $index->getName(); }, $indicesWithAlias)); diff --git a/test/lib/Elastica/Test/Suggest/PhraseTest.php b/test/lib/Elastica/Test/Suggest/PhraseTest.php index fda5ae7971..1118b87195 100644 --- a/test/lib/Elastica/Test/Suggest/PhraseTest.php +++ b/test/lib/Elastica/Test/Suggest/PhraseTest.php @@ -21,7 +21,7 @@ class PhraseTest extends BaseTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex('test_suggest_phrase'); + $this->_index = $this->_createIndex(); $docs = array(); $docs[] = new Document(1, array('text' => 'Github is pretty cool')); $docs[] = new Document(2, array('text' => 'Elasticsearch is bonsai cool')); @@ -33,11 +33,6 @@ protected function setUp() $this->_index->refresh(); } - protected function tearDown() - { - $this->_index->delete(); - } - public function testToArray() { $suggest = new Suggest(); diff --git a/test/lib/Elastica/Test/Suggest/TermTest.php b/test/lib/Elastica/Test/Suggest/TermTest.php index 205fa25eb2..0d62e58b04 100644 --- a/test/lib/Elastica/Test/Suggest/TermTest.php +++ b/test/lib/Elastica/Test/Suggest/TermTest.php @@ -20,7 +20,7 @@ class TermTest extends BaseTest protected function setUp() { parent::setUp(); - $this->_index = $this->_createIndex('test_suggest'); + $this->_index = $this->_createIndex(); $docs = array(); $docs[] = new Document(1, array('id' => 1, 'text' => 'GitHub')); $docs[] = new Document(2, array('id' => 1, 'text' => 'Elastic')); @@ -33,11 +33,6 @@ protected function setUp() $this->_index->refresh(); } - protected function tearDown() - { - $this->_index->delete(); - } - public function testToArray() { $suggest = new Suggest(); diff --git a/test/lib/Elastica/Test/Transport/MemcacheTest.php b/test/lib/Elastica/Test/Transport/MemcacheTest.php index a3fcb3d318..7830194d43 100644 --- a/test/lib/Elastica/Test/Transport/MemcacheTest.php +++ b/test/lib/Elastica/Test/Transport/MemcacheTest.php @@ -36,7 +36,7 @@ public function testConstruct() public function testCreateDocument() { - $index = $this->_createIndex('memcache_test'); + $index = $this->_createIndex(); $this->_waitForAllocation($index); $type = $index->getType('foo'); @@ -55,7 +55,7 @@ public function testCreateDocument() */ public function testDeleteDocument() { - $index = $this->_createIndex('memcache_test'); + $index = $this->_createIndex(); $this->_waitForAllocation($index); $type = $index->getType('foo'); @@ -73,7 +73,7 @@ public function testDeleteDocument() public function testUpdateDocument() { - $index = $this->_createIndex('memcache_test'); + $index = $this->_createIndex(); $this->_waitForAllocation($index); $type = $index->getType('foo'); @@ -98,7 +98,7 @@ public function testUpdateDocument() public function testSearchDocument() { - $index = $this->_createIndex('memcache_test'); + $index = $this->_createIndex(); $this->_waitForAllocation($index); $type = $index->getType('fruits'); @@ -149,7 +149,7 @@ public function testInvalidRequest() */ public function testRequestWithLongPath() { - $index = $this->_createIndex('memcache_test'); + $index = $this->_createIndex(); $this->_waitForAllocation($index); $queryString = new QueryString(str_repeat('z', 300)); diff --git a/test/lib/Elastica/Test/TypeTest.php b/test/lib/Elastica/Test/TypeTest.php index 0da79f5e0d..e09242934a 100644 --- a/test/lib/Elastica/Test/TypeTest.php +++ b/test/lib/Elastica/Test/TypeTest.php @@ -398,7 +398,7 @@ public function testDeleteByQueryWithQuery() public function testDeleteByQueryWithQueryAndOptions() { - $index = $this->_createIndex('test', true, 2); + $index = $this->_createIndex(null, true, 2); $type = new Type($index, 'test'); $type->addDocument(new Document(1, array('name' => 'ruflin nicolas'))); $type->addDocument(new Document(2, array('name' => 'ruflin'))); @@ -501,7 +501,12 @@ public function testDeleteType() $type->addDocument(new Document(2, array('name' => 'ruflin'))); $index->refresh(); + // sleep a moment to be sure that all nodes in cluster has new type + sleep(5); + $type->delete(); + $index->optimize(); + $this->assertFalse($type->exists()); } @@ -824,6 +829,9 @@ public function testExists() $type->addDocument(new Document(1, array('name' => 'test name'))); $index->optimize(); + // sleep a moment to be sure that all nodes in cluster has new type + sleep(5); + //Test if type exists $this->assertTrue($type->exists()); @@ -833,10 +841,9 @@ public function testExists() public function testGetMapping() { - $indexName = 'test'; $typeName = 'test-type'; - $index = $this->_createIndex($indexName); + $index = $this->_createIndex(); $indexName = $index->getName(); $type = new Type($index, $typeName); $mapping = new Mapping($type, $expect = array( @@ -854,11 +861,10 @@ public function testGetMapping() public function testGetMappingAlias() { - $indexName = 'test'; $aliasName = 'test-alias'; $typeName = 'test-alias-type'; - $index = $this->_createIndex($indexName); + $index = $this->_createIndex(); $index->addAlias($aliasName); $type = new Type($index, $typeName); $mapping = new Mapping($type, $expect = array( diff --git a/test/shutdown/ShutdownTest.php b/test/shutdown/ShutdownTest.php index 82c018ac9e..641a863575 100644 --- a/test/shutdown/ShutdownTest.php +++ b/test/shutdown/ShutdownTest.php @@ -8,24 +8,28 @@ */ class ShutdownTest extends BaseTest { - /** - * @test - */ - public function nodeShutdown() + protected function tearDown() + { + // We can't use Elastica\Test\Base::tearDown here, + // because cluster was shutted down and indices can't be anymore deleted. + // So, just do nothing + } + + public function testNodeShutdown() { // Get cluster nodes $client = $this->_getClient(); $cluster = $client->getCluster(); $nodes = $cluster->getNodes(); - if (count($nodes) < 3) { - $this->markTestIncomplete('At least three nodes have to be running, because 1 node is shutdown'); + if (count($nodes) < 2) { + $this->markTestIncomplete('At least two nodes have to be running, because 1 node is shutdown'); } // sayonara, wolverine, we'd never love you foreach ($nodes as $node) { - if ($node->getName() === 'Wolverine') { - $node->shutdown('2s'); + if ((int)$node->getInfo()->getPort() === 9201) { + $node->shutdown('1s'); break; } } @@ -38,30 +42,28 @@ public function nodeShutdown() $cluster = $client->getCluster(); $nodes = $cluster->getNodes(); - // Only two left - $this->assertCount(2, $nodes); + // Only one left + $this->assertCount(1, $nodes); } /** - * @test - * @depends nodeShutdown - * @expectedException \Elastica\Exception\ConnectionException + * @depends testNodeShutdown + * @expectedException \Elastica\Exception\Connection\HttpException */ - public function clusterShutdown() + public function testClusterShutdown() { // Get cluster nodes $client = $this->_getClient(); $cluster = $client->getCluster(); $nodes = $cluster->getNodes(); - if (count($nodes) < 2) { - $this->markTestIncomplete('At least two nodes have to be running, because we shuts down entire cluster'); - } - - $cluster->shutdown('2s'); + // Shutdown cluster + $cluster->shutdown('1s'); + // Wait... sleep(5); + // Now exception must be thrown $client->getStatus(); } }