Skip to content
This repository has been archived by the owner on Mar 6, 2021. It is now read-only.

Commit

Permalink
#38
Browse files Browse the repository at this point in the history
git-svn-id: https://www.dropr.org/svn/trunk@177 f77b8f78-39ad-454d-97bc-04c3ead53514
  • Loading branch information
Soenke Ruempler committed Aug 16, 2008
1 parent a690ecc commit 7d1e9fd
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 38 deletions.
13 changes: 10 additions & 3 deletions classes/Server/Storage/Abstract.php
Expand Up @@ -49,6 +49,13 @@ abstract class dropr_Server_Storage_Abstract
const TYPE_FILE = 3; 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) public static function factory($type, $dsn)
{ {
$className = 'dropr_Server_Storage_' . ucfirst($type); $className = 'dropr_Server_Storage_' . ucfirst($type);
Expand All @@ -67,16 +74,16 @@ abstract public function pollProcessed($messageId);
/** /**
* @return array * @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 * 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 * from the list of active messages to it's not in list of getMessages
* anymore * 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); abstract public function setProcessed(dropr_Server_Message $message);


Expand Down
25 changes: 17 additions & 8 deletions classes/Server/Storage/Filesystem.php
Expand Up @@ -81,22 +81,31 @@ protected function __construct($path)
public function put(dropr_Server_Message $message) public function put(dropr_Server_Message $message)
{ {
$mHandle = $message->getMessage(); $mHandle = $message->getMessage();
if ($mHandle instanceof SplFileInfo) { if ($mHandle instanceof SplFileInfo || is_string($mHandle)) {
// XXX typ!
// xxx auslagern in eigene funktion // xxx auslagern in eigene funktion


$src = $mHandle->getPathname();
$proc = $this->buildMessagePath($message, self::SPOOLDIR_TYPE_SPOOL); $proc = $this->buildMessagePath($message, self::SPOOLDIR_TYPE_SPOOL);
$done = $this->buildMessagePath($message, self::SPOOLDIR_TYPE_PROCESSED); $done = $this->buildMessagePath($message, self::SPOOLDIR_TYPE_PROCESSED);

if (file_exists ($proc) || file_exists ($done)) { if (file_exists ($proc) || file_exists ($done)) {
// the message has already been stored
// XXX write test!
return; return;
} }


// sometimes php throws a warning but returns true and the file is moved if ($mHandle instanceof SplFileInfo) {
// .. maybe NFS issue so we have to use the @-operator // handle is a file, move it
if (!@rename($src, $proc)) { $src = $mHandle->getPathname();
throw new dropr_Server_Exception("Could not save $src to $proc");
// 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 { } else {
throw new dropr_Server_Exception('not implemented'); throw new dropr_Server_Exception('not implemented');
Expand Down
98 changes: 98 additions & 0 deletions tests/server/LocalFilesystemTransportTest.php
@@ -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);
}
}
}
27 changes: 0 additions & 27 deletions tests/server/server.php

This file was deleted.

0 comments on commit 7d1e9fd

Please sign in to comment.