Beispiel #1
0
 /**
  * Cleans test folders in the temporary directory.
  *
  * @BeforeSuite
  * @AfterSuite
  */
 public static function cleanTestFolders()
 {
     if (is_dir($dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'php-driver')) {
         self::clearDirectory($dir);
     }
     $ccm = new \CCM('', '');
     $ccm->removeAllClusters();
 }
Beispiel #2
0
 /**
  * Create the integration helper instance.
  *
  * @param $className Name of the class for the executed test.
  * @param string $testName Name of the test being executed.
  * @param int $numberDC1Nodes Number of nodes in data center one
  *                            (DEFAULT: 1).
  * @param int $numberDC2Nodes Number of nodes in data center two
  *                            (DEFAULT: 0).
  * @param bool $isClientAuthentication True if client authentication
  *                                     should be enabled; false
  *                                     otherwise (DEFAULT: false).
  * @param bool $isSSL True if SSL should be enabled; false otherwise
  *                    (DEFAULT: false).
  * @return Integration Instance of the Integration class created.
  */
 public function __construct($className, $testName = "", $numberDC1Nodes = 1, $numberDC2Nodes = 0, $isClientAuthentication = false, $isSSL = false)
 {
     // Generate the keyspace name for the test
     $this->keyspaceName = $this->getShortName($className);
     if (!empty($testName)) {
         $this->keyspaceName = $this->keyspaceName . "_" . $testName;
     }
     // Make all strings lowercase for case insensitive O/S (e.g. Windows)
     $this->keyspaceName = strtolower($this->keyspaceName);
     //Ensure the keyspace does not contain more to many characters
     if (strlen($this->keyspaceName) > self::KEYSPACE_MAXIMUM_LENGTH) {
         // Update the keyspace name with a unique ID
         $uniqueID = uniqid();
         $this->keyspaceName = substr($this->keyspaceName, 0, self::KEYSPACE_MAXIMUM_LENGTH - strlen($uniqueID)) . $uniqueID;
     }
     // Create the Cassandra cluster for the test
     //TODO: Need to add the ability to switch the Cassandra version (command line)
     $this->ccm = new \CCM(self::CASSANDRA_VERSION, self::IS_CCM_SILENT);
     $this->ccm->setup($numberDC1Nodes, $numberDC2Nodes);
     if ($isClientAuthentication) {
         $this->ccm->setupClientVerification();
     }
     if ($isSSL) {
         $this->ccm->setupSSL();
     }
     $this->ccm->start();
     // Determine replication strategy and generate the query
     $replicationStrategy = "'SimpleStrategy', 'replication_factor': ";
     if ($numberDC2Nodes > 0) {
         $replicationStrategy = "'NetworkTopologyStrategy', 'dc1': " . $numberDC1Nodes . ", " . "'dc2': " . $numberDC2Nodes;
     } else {
         $replicationFactor = $numberDC1Nodes % 2 == 0 ? $numberDC1Nodes / 2 : ($numberDC1Nodes + 1) / 2;
         $replicationStrategy .= $replicationFactor;
     }
     $query = sprintf(Integration::SIMPLE_KEYSPACE_FORMAT, $this->keyspaceName, $replicationStrategy);
     // Create the session and keyspace for the integration test
     try {
         // Create the session and integration test keypspace
         $this->cluster = \Cassandra::cluster()->withContactPoints(Integration::IP_ADDRESS)->build();
         $this->session = $this->cluster->connect();
         $statement = new SimpleStatement($query);
         $this->session->execute($statement);
         // Update the session to use the new keyspace by default
         $statement = new SimpleStatement("USE " . $this->keyspaceName);
         $this->session->execute($statement);
         // Get the server version the session is connected to
         $statement = new SimpleStatement(self::SELECT_SERVER_VERSION);
         $rows = $this->session->execute($statement);
         $this->serverVersion = $rows->first()["release_version"];
     } catch (Exception $e) {
         printf("Error Creating CCM Cluster: %s" . PHP_EOL . "%s" . PHP_EOL, $e->getMessage(), $e->getTraceAsString());
     }
 }
Beispiel #3
0
 /**
  * Destroy all CCM clusters when starting and stopping the integration tests.
  * This will only be run on startup and shutdown.
  */
 private function removeTestClusters()
 {
     $ccm = new \CCM(CCM::DEFAULT_CASSANDRA_VERSION, true);
     $ccm->removeAllClusters();
 }
Beispiel #4
0
 function __destruct()
 {
     $this->ccm->removeAllClusters();
 }