// Grab a random character from our list $r = $chars[rand(0, $chars_length)]; // Make sure the same two characters don't appear next to each other if ($r != $string[$i - 1]) { $string .= $r; } } // Return the string return $string; } // generate 5 timestamped supercolumns for ($i = 1; $i <= 5; $i++) { $bp = new BlogPost(UUID::v1()); $bp->column_title = rand_str(); $bp->column_body = rand_str(); $scf->addSuper($bp); } echo 'Saving SuperColumnFamily...<br>'; print_r($scf->toJSON()); $scf->save(); // get slice of the 5 most recent entries (count = 5, reversed = true) echo '<br><br>Loading via SuperColumnFamily container...<br>'; $scNew = new PandraSuperColumnFamily($keyID, $ks, $cfName, PandraColumnContainer::TYPE_UUID); $scNew->limit(5)->load(); echo '<br>Loaded...<br>'; print_r($scNew->toJSON()); echo '<br><br>Loading SuperColumn Slice...<br>'; $result = PandraCore::getCFSlice($ks, $keyID, new cassandra_ColumnParent(array('column_family' => $cfName)), new PandraSlicePredicate(PandraSlicePredicate::TYPE_RANGE, array('start' => '', 'finish' => '', 'count' => 5, 'reversed' => true))); $scNew = new PandraSuperColumnFamily($keyID, $ks, $cfName, PandraColumnContainer::TYPE_UUID); var_dump($result); $scNew->populate($result);
public function testNotations() { $superName = 'blog-slug-3'; $colName = 'title'; $value = 'Another blog by me'; // --------- Array Access // // Test Super add $this->obj[$superName] = new TestSuperColumn($superName); $this->assertTrue($this->obj[$superName] instanceof PandraSuperColumn); // Check column name and not column name are correctly set $this->obj->reset(); $this->assertFalse($this->obj->isModified()); $this->obj[$superName][$colName] = $value; $this->assertTrue($this->obj->isModified()); $this->assertTrue($this->obj[$superName][$colName] == $value); $this->assertFalse($this->obj[$superName]['NOT_' . $colName] == $value); // Unset unset($this->obj[$superName][$colName]); $this->assertTrue($this->obj[$superName][$colName] == NULL); unset($this->obj[$superName]); $this->assertTrue($this->obj[$superName] == NULL); // --------- Magic Methods // Test Super Add $superPath = PandraSuperColumnFamily::_columnNamePrefix . $superName; $columnPath = PandraColumnFamily::_columnNamePrefix . $colName; $this->obj->{$superPath} = new TestSuperColumn($superName); $this->assertTrue($this->obj->{$superPath} instanceof PandraSuperColumn); // Check column name and not column name are correctly set $this->obj->reset(); $this->assertFalse($this->obj->isModified()); $this->obj->{$superPath}->{$columnPath} = $value; $this->assertTrue($this->obj->isModified()); $this->assertTrue($this->obj->{$superPath}->{$columnPath} == $value); $nColumnPath = 'NOT_' . $columnPath; $this->assertFalse($this->obj->{$superPath}->{$nColumnPath} == $value); // Unset //unset($this->obj[$superName][$colName]); $this->obj->{$superPath}->destroyColumns($colName); $this->assertTrue($this->obj->{$superPath}->{$columnPath} == NULL); $this->obj->destroyColumns($superName); $this->assertTrue($this->obj->{$superPath} == NULL); // --------- Accessors/Mutators // Test Super Add $superPath = PandraSuperColumnFamily::_columnNamePrefix . $superName; $columnPath = PandraColumnFamily::_columnNamePrefix . $colName; $this->obj->addSuper(new TestSuperColumn($superName)); $this->assertTrue($this->obj->getSuper($superName) instanceof PandraSuperColumn); // Check column name and not column name are correctly set $this->obj->reset(); $this->assertFalse($this->obj->isModified()); $this->obj->getSuper($superName)->getColumn($colName)->setValue($value); $this->assertTrue($this->obj->isModified()); $this->assertTrue($this->obj->getSuper($superName)->getColumn($colName)->value == $value); $this->assertFalse($this->obj->getSuper($superName)->getColumn('NOT_' . $colName)->value == $value); // Unset unset($this->obj[$superName][$colName]); $this->obj->getSuper($superName)->destroyColumns($colName); $this->assertTrue($this->obj->getSuper($superName)->getColumn($colName) == NULL); unset($this->obj[$superName]); $this->obj->destroyColumns($superName); $this->assertTrue($this->obj->getSuper($superName) == NULL); }