Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
4509519b
Commit
4509519b
authored
Mar 13, 2012
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parallelexecution plugin now uses endpoints.
Also updated unittest
parent
d56401c3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
34 deletions
+30
-34
library/Solarium/Plugin/ParallelExecution.php
library/Solarium/Plugin/ParallelExecution.php
+19
-20
tests/Solarium/Tests/Plugin/ParallelExecutionTest.php
tests/Solarium/Tests/Plugin/ParallelExecutionTest.php
+11
-14
No files found.
library/Solarium/Plugin/ParallelExecution.php
View file @
4509519b
...
...
@@ -78,21 +78,31 @@ class ParallelExecution extends Plugin
*/
protected
$queries
=
array
();
/**
* Set curl adapter (the only type that supports parallelexecution)
*/
protected
function
initPluginType
()
{
$this
->
client
->
setAdapter
(
'Solarium\Client\Adapter\Curl'
);
}
/**
* Add a query to execute
*
* @param string $key
* @param Query $query
* @param null|
Client $clie
nt
* @param null|
string|Endpoint $endpoi
nt
* @return self Provides fluent interface
*/
public
function
addQuery
(
$key
,
$query
,
$
clie
nt
=
null
)
public
function
addQuery
(
$key
,
$query
,
$
endpoi
nt
=
null
)
{
if
(
$client
==
null
)
$client
=
$this
->
client
;
if
(
is_object
(
$endpoint
))
$endpoint
=
$endpoint
->
getKey
();
if
(
$endpoint
==
null
)
$endpoint
=
$this
->
client
->
getEndpoint
()
->
getKey
();
$this
->
queries
[
$key
]
=
array
(
'query'
=>
$query
,
'
client'
=>
$clie
nt
,
'
endpoint'
=>
$endpoi
nt
,
);
return
$this
;
...
...
@@ -124,29 +134,18 @@ class ParallelExecution extends Plugin
/**
* Execute queries parallel
*
* Use an array of Solarium_Query objects as input. The keys of the array are important, as they are also used in
* the result array. You can mix all querytypes in the input array.
*
* @param array $queries (deprecated, use addQuery instead)
* @return array
*/
public
function
execute
(
$queries
=
null
)
public
function
execute
()
{
// this is for backwards compatibility
if
(
is_array
(
$queries
))
{
foreach
(
$queries
as
$key
=>
$query
)
{
$this
->
addQuery
(
$key
,
$query
);
}
}
// create handles and add all handles to the multihandle
$adapter
=
$this
->
client
->
getAdapter
();
$multiHandle
=
curl_multi_init
();
$handles
=
array
();
foreach
(
$this
->
queries
as
$key
=>
$data
)
{
$request
=
$this
->
client
->
createRequest
(
$data
[
'query'
]);
$
adapter
=
$data
[
'client'
]
->
setAdapter
(
'Solarium\Client\Adapter\Curl'
)
->
getAdapter
(
);
$handle
=
$adapter
->
createHandle
(
$request
);
$
endpoint
=
$this
->
client
->
getEndpoint
(
$data
[
'endpoint'
]
);
$handle
=
$adapter
->
createHandle
(
$request
,
$endpoint
);
curl_multi_add_handle
(
$multiHandle
,
$handle
);
$handles
[
$key
]
=
$handle
;
}
...
...
@@ -175,7 +174,7 @@ class ParallelExecution extends Plugin
try
{
curl_multi_remove_handle
(
$multiHandle
,
$handle
);
$response
=
$adapter
->
getResponse
(
$handle
,
curl_multi_getcontent
(
$handle
));
$results
[
$key
]
=
$this
->
client
->
createResult
(
$queries
[
$key
][
'query'
],
$response
);
$results
[
$key
]
=
$this
->
client
->
createResult
(
$
this
->
queries
[
$key
][
'query'
],
$response
);
}
catch
(
HttpException
$e
)
{
$results
[
$key
]
=
$e
;
...
...
tests/Solarium/Tests/Plugin/ParallelExecutionTest.php
View file @
4509519b
...
...
@@ -48,26 +48,23 @@ class ParallelExecutionTest extends \PHPUnit_Framework_TestCase
public
function
testAddAndGetQueries
()
{
$client1
=
new
Client
();
$client2
=
new
Client
(
array
(
'adapter'
=>
'MyAdapter'
,
'adapteroptions'
=>
array
(
'host'
=>
'myhost'
,
)
)
);
$this
->
plugin
->
initPlugin
(
$client1
,
array
());
$client
=
new
Client
();
$client
->
clearEndpoints
();
$client
->
createEndpoint
(
'local1'
);
$endpoint2
=
$client
->
createEndpoint
(
'local2'
);
$this
->
plugin
->
initPlugin
(
$client
,
array
());
$query1
=
$client
1
->
createSelect
()
->
setQuery
(
'test1'
);
$query2
=
$client
1
->
createSelect
()
->
setQuery
(
'test2'
);
$query1
=
$client
->
createSelect
()
->
setQuery
(
'test1'
);
$query2
=
$client
->
createSelect
()
->
setQuery
(
'test2'
);
$this
->
plugin
->
addQuery
(
1
,
$query1
);
$this
->
plugin
->
addQuery
(
2
,
$query2
,
$
clie
nt2
);
$this
->
plugin
->
addQuery
(
2
,
$query2
,
$
endpoi
nt2
);
$this
->
assertEquals
(
array
(
1
=>
array
(
'query'
=>
$query1
,
'
client'
=>
$client1
),
2
=>
array
(
'query'
=>
$query2
,
'
client'
=>
$client2
),
1
=>
array
(
'query'
=>
$query1
,
'
endpoint'
=>
'local1'
),
2
=>
array
(
'query'
=>
$query2
,
'
endpoint'
=>
'local2'
),
),
$this
->
plugin
->
getQueries
()
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment