public function testGetActiveTasks()
 {
     $client = $this->couchClient;
     $active_tasks = $client->getActiveTasks();
     $this->assertEquals(array(), $active_tasks);
     $sourceDatabase = $this->getTestDatabase();
     $targetDatabase1 = $this->getTestDatabase() . 'target1';
     $targetDatabase2 = $this->getTestDatabase() . 'target2';
     $this->couchClient->deleteDatabase($targetDatabase1);
     $this->couchClient->deleteDatabase($targetDatabase2);
     $this->couchClient->createDatabase($targetDatabase1);
     $this->couchClient->createDatabase($targetDatabase2);
     $client->replicate($sourceDatabase, $targetDatabase1, null, true);
     $active_tasks = $client->getActiveTasks();
     $this->assertTrue(count($active_tasks) == 1);
     $client->replicate($sourceDatabase, $targetDatabase2, null, true);
     $active_tasks = $client->getActiveTasks();
     $this->assertTrue(count($active_tasks) == 2);
     $client->replicate($sourceDatabase, $targetDatabase1, true, true);
     $client->replicate($sourceDatabase, $targetDatabase2, true, true);
     $active_tasks = $client->getActiveTasks();
     $this->assertEquals(array(), $active_tasks);
     // Tidy
     $this->couchClient->deleteDatabase($targetDatabase1);
     $this->couchClient->deleteDatabase($targetDatabase2);
 }
 /**
  * @return array
  * @throws HTTPException
  * @throws \Exception
  */
 public function verifyPeers()
 {
     $sourceInfo = null;
     try {
         $sourceInfo = $this->source->getDatabaseInfo($this->source->getDatabase());
     } catch (HTTPException $e) {
         throw new \Exception('Source not reachable.');
     }
     $targetInfo = null;
     try {
         $targetInfo = $this->target->getDatabaseInfo($this->target->getDatabase());
     } catch (HTTPException $e) {
         if ($e->getCode() == 404 && $this->task->getCreateTarget()) {
             $this->target->createDatabase($this->target->getDatabase());
             $targetInfo = $this->target->getDatabaseInfo($this->target->getDatabase());
         } else {
             throw new \Exception("Target database does not exist.");
         }
     }
     return array($sourceInfo, $targetInfo);
 }
 public function setUp()
 {
     $this->couchClient = $this->createCouchDBClientForBulkTest();
     $this->couchClient->createDatabase($this->getBulkTestDatabase());
     $this->bulkUpdater = $this->couchClient->createBulkUpdater();
 }
 public function testRequestSuccessWithAttachments()
 {
     $client = new CouchDBClient($this->getHttpClient(), $this->getTestDatabase());
     // Recreate DB
     $client->deleteDatabase($this->getTestDatabase());
     $client->createDatabase($this->getTestDatabase());
     // Doc id.
     $id = $this->docId;
     // Document with attachments.
     $docWithAttachment = array('_id' => $id, '_rev' => '1-abc', '_attachments' => array('foo.txt' => array('content_type' => 'text/plain', 'data' => 'VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ='), 'bar.txt' => array('content_type' => 'text/plain', 'data' => 'VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=')));
     // Doc without any attachment. The id of both the docs is same.
     // So we will get two leaf revisions.
     $doc = array('_id' => $id, 'foo' => 'bar', '_rev' => '1-bcd');
     // Add the documents to the test db using Bulk API.
     $updater = $client->createBulkUpdater();
     $updater->updateDocument($docWithAttachment);
     $updater->updateDocument($doc);
     // Set newedits to false to use the supplied _rev instead of assigning
     // new ones.
     $updater->setNewEdits(false);
     $response = $updater->execute();
     // Create the copy database and a copyClient to interact with it.
     $copyDb = $this->getTestDatabase() . '_multipart_copy';
     $client->createDatabase($copyDb);
     $copyClient = new CouchDBClient($client->getHttpClient(), $copyDb);
     // Missing revisions in the $copyDb.
     $missingRevs = array('1-abc', '1-bcd');
     $this->sourceParams['open_revs'] = json_encode($missingRevs);
     $query = http_build_query($this->sourceParams);
     $this->sourcePath .= '?' . $query;
     // Get the multipart data stream from real CouchDB instance.
     $stream = (new StreamClient())->getConnection($this->sourceMethod, $this->sourcePath, null, $this->sourceHeaders);
     // Set the return values for the mocked StreamClient.
     $this->streamClientMock->expects($this->once())->method('getConnection')->willReturn($stream);
     // Return header with status code as 200.
     $this->streamClientMock->expects($this->once())->method('getStreamHeaders')->willReturn(array('status' => 200));
     // Transfer the missing revisions from the source to the target.
     list($docStack, $responses) = $this->parserAndSender->request($this->sourceMethod, $this->sourcePath, $this->targetPath, null, $this->sourceHeaders);
     // $docStack should contain the doc that didn't have the attachment.
     $this->assertEquals(1, count($docStack));
     $this->assertEquals($doc, json_decode($docStack[0], true));
     // The doc with attachment should have been copied to the copyDb.
     $this->assertEquals(1, count($responses));
     $this->assertArrayHasKey('ok', $responses[0]);
     $this->assertEquals(true, $responses[0]['ok']);
     // Clean up.
     $client->deleteDatabase($this->getTestDatabase());
     $client->createDatabase($this->getTestDatabase());
     $client->deleteDatabase($copyDb);
 }
Beispiel #5
0
 /**
  * @param \Doctrine\CouchDB\CouchDBClient $client
  * @param string                          $database
  * @param bool                            $createIfNotFound
  *
  * @return bool Returns TRUE ONLY when the database existed before the call.
  * @throws \Doctrine\CouchDB\HTTP\HTTPException
  */
 public static function databaseExists($client, $database = null, $createIfNotFound = true)
 {
     try {
         return $client->getDatabaseInfo($database ?: $client->getDatabase());
     } catch (\Doctrine\CouchDB\HTTP\HTTPException $_ex) {
         if (static::NotFound != $_ex->getCode()) {
             throw $_ex;
         }
         if (true === $createIfNotFound) {
             $client->createDatabase($database ?: $client->getDatabase());
         }
     }
     return false;
 }
 /**
  * @depends testCreateDatabase
  */
 public function testCreateDuplicateDatabaseThrowsException()
 {
     $this->couchClient->createDatabase($this->getTestDatabase());
     $this->setExpectedException('Doctrine\\CouchDB\\HTTP\\HTTPException', 'HTTP Error with status 412 occoured while requesting /' . $this->getTestDatabase() . '. Error: file_exists The database could not be created, the file already exists.');
     $this->couchClient->createDatabase($this->getTestDatabase());
 }