Ejemplo n.º 1
0
 public function testCreating()
 {
     $event = new Edo_Event();
     $data = $event->toArray();
     unset($data['time_started']);
     $expected = array('id' => null, 'ref' => null, 'event' => null, 'tag' => null, 'body' => null, 'lang' => null, 'attempts_made' => 0);
     $this->assertEquals($expected, $data);
     //create 2
     $input_data = array('id' => 'some_id', 'ref' => '/article/2');
     $event = new Edo_Event($input_data);
     $data = $event->toArray();
     unset($data['time_started']);
     $expected = array('id' => 'some_id', 'ref' => '/article/2', 'event' => null, 'tag' => null, 'body' => null, 'lang' => null, 'attempts_made' => 0);
     $this->assertEquals($expected, $data);
 }
Ejemplo n.º 2
0
 protected function _saveEvent($worker_name, Edo_Event $event, $isCreate = false)
 {
     $path = $this->getDirPath($worker_name);
     $event_path = $path . DIRECTORY_SEPARATOR . $event->id;
     $fp = $this->getFp($event->id, $worker_name);
     if (!$fp && !$isCreate) {
         throw new Edo_Event_Engine_Exception("No lock acquired on event {$event->id} in pool {$worker_name}. Update canceled;");
     } elseif ($isCreate) {
         $fp = fopen($event_path, "w+");
         @chmod($event_path, 0666);
         if (flock($fp, LOCK_EX | LOCK_NB)) {
             $this->fp_locks[$this->getFpIndex($event->id, $worker_name)] = $fp;
         } else {
             throw new Edo_Event_Engine_Exception("Unable to acquire lock on creating new file {$event_path}");
         }
     }
     rewind($fp);
     ftruncate($fp, 0);
     $bytesWritten = fwrite($fp, json_encode($event->toArray()));
     return (bool) $bytesWritten;
 }