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
10ffdc8c
Commit
10ffdc8c
authored
Mar 12, 2013
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Plain Diff
merging 3.1 release changes into develop
parents
d24c8333
d733309d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
173 additions
and
6 deletions
+173
-6
library/Solarium/Plugin/BufferedAdd/BufferedAdd.php
library/Solarium/Plugin/BufferedAdd/BufferedAdd.php
+7
-2
library/Solarium/Plugin/BufferedAdd/Event/AddDocument.php
library/Solarium/Plugin/BufferedAdd/Event/AddDocument.php
+75
-0
library/Solarium/Plugin/BufferedAdd/Event/Events.php
library/Solarium/Plugin/BufferedAdd/Event/Events.php
+9
-0
tests/Solarium/Tests/Plugin/BufferedAdd/BufferedAddTest.php
tests/Solarium/Tests/Plugin/BufferedAdd/BufferedAddTest.php
+33
-4
tests/Solarium/Tests/Plugin/BufferedAdd/Event/AddDocumentTest.php
...larium/Tests/Plugin/BufferedAdd/Event/AddDocumentTest.php
+49
-0
No files found.
library/Solarium/Plugin/BufferedAdd/BufferedAdd.php
View file @
10ffdc8c
...
@@ -47,6 +47,7 @@ use Solarium\Plugin\BufferedAdd\Event\PreFlush as PreFlushEvent;
...
@@ -47,6 +47,7 @@ use Solarium\Plugin\BufferedAdd\Event\PreFlush as PreFlushEvent;
use
Solarium\Plugin\BufferedAdd\Event\PostFlush
as
PostFlushEvent
;
use
Solarium\Plugin\BufferedAdd\Event\PostFlush
as
PostFlushEvent
;
use
Solarium\Plugin\BufferedAdd\Event\PreCommit
as
PreCommitEvent
;
use
Solarium\Plugin\BufferedAdd\Event\PreCommit
as
PreCommitEvent
;
use
Solarium\Plugin\BufferedAdd\Event\PostCommit
as
PostCommitEvent
;
use
Solarium\Plugin\BufferedAdd\Event\PostCommit
as
PostCommitEvent
;
use
Solarium\Plugin\BufferedAdd\Event\AddDocument
as
AddDocumentEvent
;
/**
/**
* Buffered add plugin
* Buffered add plugin
...
@@ -138,6 +139,10 @@ class BufferedAdd extends Plugin
...
@@ -138,6 +139,10 @@ class BufferedAdd extends Plugin
public
function
addDocument
(
$document
)
public
function
addDocument
(
$document
)
{
{
$this
->
buffer
[]
=
$document
;
$this
->
buffer
[]
=
$document
;
$event
=
new
AddDocumentEvent
(
$document
);
$this
->
client
->
getEventDispatcher
()
->
dispatch
(
Events
::
ADD_DOCUMENT
,
$event
);
if
(
count
(
$this
->
buffer
)
==
$this
->
options
[
'buffersize'
])
{
if
(
count
(
$this
->
buffer
)
==
$this
->
options
[
'buffersize'
])
{
$this
->
flush
();
$this
->
flush
();
}
}
...
@@ -206,7 +211,7 @@ class BufferedAdd extends Plugin
...
@@ -206,7 +211,7 @@ class BufferedAdd extends Plugin
$result
=
$this
->
client
->
update
(
$this
->
updateQuery
);
$result
=
$this
->
client
->
update
(
$this
->
updateQuery
);
$this
->
clear
();
$this
->
clear
();
$event
=
new
PostFlushEvent
(
$
this
->
buffer
);
$event
=
new
PostFlushEvent
(
$
result
);
$this
->
client
->
getEventDispatcher
()
->
dispatch
(
Events
::
POST_FLUSH
,
$event
);
$this
->
client
->
getEventDispatcher
()
->
dispatch
(
Events
::
POST_FLUSH
,
$event
);
return
$result
;
return
$result
;
...
@@ -233,7 +238,7 @@ class BufferedAdd extends Plugin
...
@@ -233,7 +238,7 @@ class BufferedAdd extends Plugin
$result
=
$this
->
client
->
update
(
$this
->
updateQuery
);
$result
=
$this
->
client
->
update
(
$this
->
updateQuery
);
$this
->
clear
();
$this
->
clear
();
$event
=
new
PostCommitEvent
(
$
this
->
buffer
);
$event
=
new
PostCommitEvent
(
$
result
);
$this
->
client
->
getEventDispatcher
()
->
dispatch
(
Events
::
POST_COMMIT
,
$event
);
$this
->
client
->
getEventDispatcher
()
->
dispatch
(
Events
::
POST_COMMIT
,
$event
);
return
$result
;
return
$result
;
...
...
library/Solarium/Plugin/BufferedAdd/Event/AddDocument.php
0 → 100644
View file @
10ffdc8c
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace
Solarium\Plugin\BufferedAdd\Event
;
use
Symfony\Component\EventDispatcher\Event
;
use
Solarium\QueryType\Update\Result
;
use
Solarium\QueryType\Select\Result\DocumentInterface
;
/**
* AddDocument event, see Events for details
*/
class
AddDocument
extends
Event
{
/**
* @var DocumentInterface
*/
protected
$document
;
/**
* Event constructor
*
* @param DocumentInterface $document
*/
public
function
__construct
(
$document
)
{
$this
->
document
=
$document
;
}
/**
* Get the result for this event
*
* @return DocumentInterface
*/
public
function
getDocument
()
{
return
$this
->
document
;
}
}
library/Solarium/Plugin/BufferedAdd/Event/Events.php
View file @
10ffdc8c
...
@@ -79,4 +79,13 @@ class Events
...
@@ -79,4 +79,13 @@ class Events
* @var string
* @var string
*/
*/
const
POST_COMMIT
=
'solarium.bufferedAdd.postCommit'
;
const
POST_COMMIT
=
'solarium.bufferedAdd.postCommit'
;
/**
* This event is called when a new document is added
*
* The event listener receives the Document
*
* @var string
*/
const
ADD_DOCUMENT
=
'solarium.bufferedAdd.addDocument'
;
}
}
tests/Solarium/Tests/Plugin/BufferedAdd/BufferedAddTest.php
View file @
10ffdc8c
...
@@ -31,8 +31,10 @@
...
@@ -31,8 +31,10 @@
namespace
Solarium\Tests\Plugin\BufferedAdd
;
namespace
Solarium\Tests\Plugin\BufferedAdd
;
use
Solarium\QueryType\Update\Query\Document\Document
;
use
Solarium\QueryType\Update\Query\Document\Document
;
use
Solarium\Plugin\BufferedAdd\Event\AddDocument
;
use
Solarium\Plugin\BufferedAdd\BufferedAdd
;
use
Solarium\Plugin\BufferedAdd\BufferedAdd
;
use
Solarium\Core\Client\Client
;
use
Solarium\Core\Client\Client
;
use
Solarium\Plugin\BufferedAdd\Event\Events
;
class
BufferedAddTest
extends
\PHPUnit_Framework_TestCase
class
BufferedAddTest
extends
\PHPUnit_Framework_TestCase
{
{
...
@@ -93,9 +95,12 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase
...
@@ -93,9 +95,12 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase
public
function
testAddDocumentAutoFlush
()
public
function
testAddDocumentAutoFlush
()
{
{
$observer
=
$this
->
getMock
(
'Solarium\Plugin\BufferedAdd\BufferedAdd'
,
array
(
'flush'
));
$mockUpdate
=
$this
->
getMock
(
'Solarium\QueryType\Update\Query\Query'
,
array
(
'addDocuments'
));
$observer
->
expects
(
$this
->
once
())
->
method
(
'flush'
);
$mockUpdate
->
expects
(
$this
->
exactly
(
2
))
->
method
(
'addDocuments'
);
$observer
->
setBufferSize
(
1
);
$mockClient
=
$this
->
getMock
(
'Solarium\Core\Client\Client'
,
array
(
'createUpdate'
,
'update'
,
'triggerEvent'
));
$mockClient
->
expects
(
$this
->
exactly
(
3
))
->
method
(
'createUpdate'
)
->
will
(
$this
->
returnValue
(
$mockUpdate
));
$mockClient
->
expects
(
$this
->
exactly
(
2
))
->
method
(
'update'
)
->
will
(
$this
->
returnValue
(
'dummyResult'
));
$doc1
=
new
Document
();
$doc1
=
new
Document
();
$doc1
->
id
=
'123'
;
$doc1
->
id
=
'123'
;
...
@@ -107,7 +112,10 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase
...
@@ -107,7 +112,10 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase
$docs
=
array
(
$doc1
,
$doc2
);
$docs
=
array
(
$doc1
,
$doc2
);
$observer
->
addDocuments
(
$docs
);
$plugin
=
new
BufferedAdd
();
$plugin
->
initPlugin
(
$mockClient
,
array
());
$plugin
->
setBufferSize
(
1
);
$plugin
->
addDocuments
(
$docs
);
}
}
public
function
testClear
()
public
function
testClear
()
...
@@ -166,4 +174,25 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase
...
@@ -166,4 +174,25 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
'dummyResult'
,
$plugin
->
commit
(
true
,
false
,
true
,
false
));
$this
->
assertEquals
(
'dummyResult'
,
$plugin
->
commit
(
true
,
false
,
true
,
false
));
}
}
public
function
testAddDocumentEventIsTriggered
()
{
$data
=
array
(
'id'
=>
'123'
,
'name'
=>
'test'
);
$doc
=
new
Document
(
$data
);
$expectedEvent
=
new
AddDocument
(
$doc
);
$mockEventDispatcher
=
$this
->
getMock
(
'Solarium\QueryType\Update\Query\Query'
,
array
(
'dispatch'
));
$mockEventDispatcher
->
expects
(
$this
->
once
())
->
method
(
'dispatch'
)
->
with
(
$this
->
equalTo
(
Events
::
ADD_DOCUMENT
),
$this
->
equalTo
(
$expectedEvent
));
$mockClient
=
$this
->
getMock
(
'Solarium\Core\Client\Client'
,
array
(
'getEventDispatcher'
));
$mockClient
->
expects
(
$this
->
once
())
->
method
(
'getEventDispatcher'
)
->
will
(
$this
->
returnValue
(
$mockEventDispatcher
));
$plugin
=
new
BufferedAdd
();
$plugin
->
initPlugin
(
$mockClient
,
array
());
$plugin
->
addDocument
(
$doc
);
}
}
}
tests/Solarium/Tests/Plugin/BufferedAdd/Event/AddDocumentTest.php
0 → 100644
View file @
10ffdc8c
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
namespace
Solarium\Tests\Plugin\BufferedAdd\Event
;
use
Solarium\Plugin\BufferedAdd\Event\AddDocument
;
use
Solarium\QueryType\Update\Query\Document\Document
;
class
AddDocumentTest
extends
\PHPUnit_Framework_TestCase
{
public
function
testConstructorAndGetters
()
{
$document
=
new
Document
();
$event
=
new
AddDocument
(
$document
);
$this
->
assertEquals
(
$document
,
$event
->
getDocument
());
return
$event
;
}
}
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