public function testCreateSecondaryIndex() { $cluster = new \CouchbaseCluster('127.0.0.1'); $clusterManager = $cluster->manager('Administrator', 'Administrator'); $clusterManager->createBucket($this->bucket, ['bucketType' => 'couchbase', 'saslPassword' => '', 'flushEnabled' => true]); sleep(5); /** @var \Ytake\LaravelCouchbase\Database\CouchbaseConnection $connection */ $connection = $this->databaseManager->connection('couchbase'); $bucket = $connection->openBucket($this->bucket); $bucket->manager()->createN1qlPrimaryIndex(); sleep(4); $output = new \Symfony\Component\Console\Output\BufferedOutput(); $this->command->run(new \Symfony\Component\Console\Input\ArrayInput(['bucket' => $this->bucket, 'name' => 'testing_gsi', 'fields' => ['params1', 'params2']]), $output); $fetch = $output->fetch(); $this->assertSame("created SECONDARY INDEX [testing_gsi] fields [params1,params2], for [index_testing] bucket.", trim($fetch)); /** @var \Ytake\LaravelCouchbase\Database\CouchbaseConnection $connection */ $connection = $this->databaseManager->connection('couchbase'); $bucket = $connection->openBucket($this->bucket); $indexes = $bucket->manager()->listN1qlIndexes(); foreach ($indexes as $index) { if (!$index->isPrimary && $index->keyspace === 'keyspace') { $this->assertSame("testing_gsi", $index->name); $this->assertInstanceOf('CouchbaseN1qlIndex', $index); } } $bucket->manager()->dropN1qlPrimaryIndex(); $bucket->manager()->dropN1qlIndex('testing_gsi'); $clusterManager->removeBucket($this->bucket); }
public function testDropSecondaryIndex() { $cluster = new \CouchbaseCluster('127.0.0.1'); $clusterManager = $cluster->manager('Administrator', 'Administrator'); $clusterManager->createBucket($this->bucket, ['bucketType' => 'couchbase', 'saslPassword' => '', 'flushEnabled' => true]); sleep(5); /** @var \Ytake\LaravelCouchbase\Database\CouchbaseConnection $connection */ $connection = $this->databaseManager->connection('couchbase'); $bucket = $connection->openBucket($this->bucket); $bucket->manager()->createN1qlPrimaryIndex(); $bucket->manager()->createN1qlIndex('testing_gsi', ['params1', 'params2']); $output = new \Symfony\Component\Console\Output\BufferedOutput(); $this->command->run(new \Symfony\Component\Console\Input\ArrayInput(['bucket' => $this->bucket, 'name' => 'testing_gsi']), $output); $fetch = $output->fetch(); $this->assertSame("dropped SECONDARY INDEX [testing_gsi] for [index_testing] bucket.", trim($fetch)); $clusterManager->removeBucket($this->bucket); }
/** * @param string $bucket * * @return CouchbaseClusterManager */ protected function createBucket($bucket) { $cluster = new \CouchbaseCluster('127.0.0.1'); $clusterManager = $cluster->manager('Administrator', 'Administrator'); $clusterManager->createBucket($bucket, ['bucketType' => 'couchbase', 'saslPassword' => '', 'flushEnabled' => true]); sleep(5); return $clusterManager; }