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); }
public function tearDown() { $this->couchClient->deleteDatabase($this->getBulkTestDatabase()); }
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); }
public function testDropMultipleTimesSkips() { $this->couchClient->deleteDatabase($this->getTestDatabase()); $this->couchClient->deleteDatabase($this->getTestDatabase()); }