/**
  * Nested composite Cassandra types (list, map, set, tuple, and UDT) to be
  * used by data providers
  */
 public function nestedCassandraTypes()
 {
     $compositeCassandraTypes = $this->compositeCassandraTypes();
     foreach ($compositeCassandraTypes as $nestedType) {
         $type = Type::collection($nestedType[0]);
         $nestedCassandraTypes[] = array($type, array($type->create($nestedType[1][0])));
     }
     foreach ($compositeCassandraTypes as $nestedType) {
         $type = Type::set($nestedType[0]);
         $nestedCassandraTypes[] = array($type, array($type->create($nestedType[1][0])));
     }
     foreach ($compositeCassandraTypes as $nestedType) {
         $type = Type::map($nestedType[0], $nestedType[0]);
         $nestedCassandraTypes[] = array($type, array($type->create($nestedType[1][0], $nestedType[1][1])));
     }
     foreach ($compositeCassandraTypes as $nestedType) {
         $type = Type::tuple($nestedType[0], $nestedType[0]);
         $nestedCassandraTypes[] = array($type, array($type->create($nestedType[1][0], $nestedType[1][1])));
     }
     foreach ($compositeCassandraTypes as $nestedType) {
         $type = Type::userType("a", $nestedType[0], "b", $nestedType[0]);
         $type = $type->withName(self::userTypeString($type));
         $nestedCassandraTypes[] = array($type, array($type->create("a", $nestedType[1][0], "b", $nestedType[1][1])));
     }
     return $nestedCassandraTypes;
 }
Exemplo n.º 2
0
 /**
  * Paging advancement does not create memory leak
  *
  * This test will ensure that the driver does not create memory leaks
  * associated advancing to the next page of results.
  *
  * @test
  * @ticket PHP-101
  */
 public function testNoPagingMemoryLeak()
 {
     // Create the user types and table for the test
     $this->session->execute(new SimpleStatement("DROP TABLE {$this->tableNamePrefix}"));
     $this->session->execute(new SimpleStatement("CREATE TYPE price_history (time timestamp, price float)"));
     $priceHistory = Type::userType("time", Type::timestamp(), "price", Type::float());
     $this->session->execute(new SimpleStatement("CREATE TYPE purchase_stats (day_of_week int, total_purchases int)"));
     $purchaseStats = Type::userType("day_of_week", Type::int(), "total_purchases", Type::int());
     $this->session->execute(new SimpleStatement("CREATE TABLE {$this->tableNamePrefix} (id uuid PRIMARY KEY,\n                history frozen<price_history>, stats frozen<purchase_stats>,\n                comments text)"));
     // Populate the table with some random data
     $totalInserts = 500;
     $statement = $this->session->prepare("INSERT INTO {$this->tableNamePrefix}\n            (id, history, stats, comments) VALUES (?, ?, ?, ?)");
     foreach (range(1, $totalInserts) as $i) {
         // Create the values for the insert
         $history = $priceHistory->create("time", new Timestamp(mt_rand(1270094400000, 1459483200000)), "price", new Float(mt_rand(1, 1000) / 100));
         $stats = $purchaseStats->create("day_of_week", mt_rand(0, 6), "total_purchases", mt_rand(0, 1000));
         $values = array(new Uuid(), $history, $stats, $this->randomString());
         $options = new ExecutionOptions(array("arguments" => $values));
         $this->session->execute($statement, $options);
     }
     // Select all the rows in the table using paging
     $statement = new SimpleStatement("SELECT * FROM {$this->tableNamePrefix}");
     $options = new ExecutionOptions(array("page_size" => 2));
     $rows = $this->session->execute($statement, $options);
     // Validate paging and ensure all the rows were read
     $count = $this->validatePageResults($rows);
     $this->assertEquals($totalInserts, $count);
 }
 /**
  * Partial user type
  *
  * This test will ensure that partial user types return the correct value.
  *
  * @test
  * @ticket PHP-58
  */
 public function testPartial()
 {
     $userType = Type::userType("a", Type::int(), "b", Type::varchar(), "c", Type::bigint());
     $userType = $userType->withName(self::userTypeString($userType));
     $this->createUserType($userType);
     $user = $userType->create();
     $user->set("a", 99);
     $this->createTableInsertAndVerifyValueByIndex($userType, $user);
     $user = $userType->create();
     $user->set("b", "abc");
     $this->createTableInsertAndVerifyValueByIndex($userType, $user);
     $user = $userType->create();
     $user->set("c", new Bigint("999999999999"));
     $this->createTableInsertAndVerifyValueByIndex($userType, $user);
 }
Exemplo n.º 4
0
 public function notEqualTypes()
 {
     $setType = Type::set(Type::int());
     return array(array(Type::userType('a', Type::int(), 'b', Type::varchar(), 'c', Type::varint())->create(), Type::userType('a', Type::int(), 'b', Type::varchar(), 'c', Type::bigint())->create()), array(Type::userType('a', Type::int(), 'b', Type::varchar(), 'c', Type::bigint())->create(), Type::userType('x', Type::int(), 'y', Type::varchar(), 'z', Type::bigint())->create()), array(Type::userType('a', Type::int(), 'b', Type::varchar(), 'c', Type::bigint())->create('a', 1, 'b', 'x', 'c', new Bigint(99)), Type::userType('a', Type::int(), 'b', Type::varchar(), 'c', Type::bigint())->create('a', 2, 'b', 'y', 'c', new Bigint(999))), array(Type::userType('a', $setType, 'b', Type::varchar())->create('a', $setType->create(1, 2, 3), 'b', 'x'), Type::userType('a', $setType, 'b', Type::varchar())->create('a', $setType->create(4, 5, 6), 'b', 'x')));
 }