Permalink
Browse files

#38

git-svn-id: https://www.dropr.org/svn/trunk@177 f77b8f78-39ad-454d-97bc-04c3ead53514
  • Loading branch information...
Soenke Ruempler
Soenke Ruempler committed Aug 16, 2008
1 parent a690ecc commit 7d1e9fd0e85a74aa66e274bcadca6cdbacc16264
@@ -49,6 +49,13 @@
const TYPE_FILE = 3;
/**
* Create a server storage instance
*
* @param string $type
* @param string $dsn
* @return dropr_Server_Storage_Abstract
*/
public static function factory($type, $dsn)
{
$className = 'dropr_Server_Storage_' . ucfirst($type);
@@ -67,16 +74,16 @@ public static function factory($type, $dsn)
/**
* @return array
*/
abstract public function getMessages($type = null, $limit = null);
abstract public function getMessages($channel = 'common', $limit = null);
/**
* Sets a message to processed state - the implementation must move it out
* from the list of active messages to it's not in list of getMessages
* anymore
*
* @param pmq_Server_Message $message
* @param dropr_Server_Message $message
*
* @throws pmq_Server_Exception
* @throws dropr_Server_Exception
*/
abstract public function setProcessed(dropr_Server_Message $message);
@@ -81,22 +81,31 @@ protected function __construct($path)
public function put(dropr_Server_Message $message)
{
$mHandle = $message->getMessage();
if ($mHandle instanceof SplFileInfo) {
// XXX typ!
if ($mHandle instanceof SplFileInfo || is_string($mHandle)) {
// xxx auslagern in eigene funktion
$src = $mHandle->getPathname();
$proc = $this->buildMessagePath($message, self::SPOOLDIR_TYPE_SPOOL);
$done = $this->buildMessagePath($message, self::SPOOLDIR_TYPE_PROCESSED);
if (file_exists ($proc) || file_exists ($done)) {
// the message has already been stored
// XXX write test!
return;
}
// sometimes php throws a warning but returns true and the file is moved
// .. maybe NFS issue so we have to use the @-operator
if (!@rename($src, $proc)) {
throw new dropr_Server_Exception("Could not save $src to $proc");
if ($mHandle instanceof SplFileInfo) {
// handle is a file, move it
$src = $mHandle->getPathname();
// sometimes php throws a warning but returns true and the file is moved
// .. maybe NFS issue so we have to use the @-operator
if (!@rename($src, $proc)) {
throw new dropr_Server_Exception("Could not save $src to $proc");
}
} elseif (is_string($mHandle)) {
if (!file_put_contents($proc, $mHandle)) {
throw new dropr_Server_Exception("Could not write content to $proc!");
}
}
} else {
throw new dropr_Server_Exception('not implemented');
@@ -0,0 +1,98 @@
<?php
/**
* dropr
*
* Copyright (c) 2007 - 2008 by the dropr project https://www.dropr.org/
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of dropr nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 OWNER 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.
*
* @package dropr
* @author Soenke Ruempler <soenke@jimdo.com>
* @author Boris Erdmann <boris@jimdo.com>
* @copyright 2007-2008 Soenke Ruempler, Boris Erdmann
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
*/
/**
* test example for bypassing the client queue for local delivery
*
* basically this is an inter process communication but with
* durability (messages are written to a durable storage)
*
* @author Soenke Ruempler
*/
require dirname (__FILE__) . '/../../classes/dropr.php';
class LocalFilesystemTransportTest extends PHPUnit_Framework_TestCase
{
/**
* @var dropr_Server_Storage_Filesystem
*/
private $storage;
private $dir;
public function setUp()
{
$this->dir = dirname (__FILE__) . '/testspool/server';
$this->storage = dropr_Server_Storage_Abstract::factory('Filesystem', $this->dir);
}
public function testPut()
{
$message = new dropr_Server_Message(
'localhost',
uniqid(null, true),
$message = 'testmessage',
'common',
1,
time()
);
$this->storage->put($message);
$messages = $this->storage->getMessages('common');
$this->assertEquals(1, count($messages));
$this->assertEquals('testmessage', (string)$messages[0]);
}
protected function tearDown()
{
// cleanup queue
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->dir)) as $f) {
unlink($f);
}
}
}
View
@@ -1,27 +0,0 @@
<?php
require '../../server/classes/autoload.php';
ini_set('error_log', '/tmp/erdmann_dropr_server/errorlog');
ini_set('log_errors', 1);
$server = dropr_Server_Transport_Abstract::factory(
'HttpUpload',
dropr_Server_Storage_Abstract::factory('filesystem', '/tmp/erdmann_dropr_server/myserverqueue3')
);
#$directClass = new ServerDirectInvokeTest();
#$server->addDirectInvocationHandler($directClass);
$server->handle();
class ServerDirectInvokeTest implements dropr_Server_DirectInvocation
{
public function invokeMessage(dropr_Server_Message $message)
{
echo $message;
return true;
}
}

0 comments on commit 7d1e9fd

Please sign in to comment.