Esempio n. 1
0
 public function testSave()
 {
     $fileName = 'testfile_bucket_bucket1_' . date('Ymd_His') . '_' . uniqid('', true) . '.yml';
     $bucket = new Bucket('test_data/' . $fileName);
     $bucket->setDatadirBasePath('test_data');
     $bucket->setDataChanged(true);
     $bucket->setDistance(21);
     $this->assertEquals(21, $bucket->getDistance());
     $bucket->setMaskBit(24);
     $this->assertEquals(24, $bucket->getMaskBit());
     $bucket->setIsFull(true);
     $this->assertEquals(true, $bucket->getIsFull());
     $bucket->setIsUpper(true);
     $this->assertEquals(true, $bucket->getIsUpper());
     $bucket->setIsLower(true);
     $this->assertEquals(true, $bucket->getIsLower());
     $this->assertTrue((bool) $bucket->save());
     $bucket = new Bucket('test_data/' . $fileName);
     $this->assertTrue($bucket->load());
     $this->assertEquals(21, $bucket->getDistance());
     $this->assertEquals(24, $bucket->getMaskBit());
     $this->assertEquals(true, $bucket->getIsFull());
     $this->assertEquals(true, $bucket->getIsUpper());
     $this->assertEquals(true, $bucket->getIsLower());
 }
Esempio n. 2
0
 public function nodeEnclose(Node $node)
 {
     #fwrite(STDOUT, __FUNCTION__.''."\n");
     if (!$this->getLocalNode()) {
         throw new RuntimeException('localNode not set.');
     }
     if (!$this->rootBucket) {
         $filePath = null;
         if ($this->getDatadirBasePath()) {
             #$filePath = $this->getDatadirBasePath().'/bucket_root_'.time().'_'.mt_rand(1000, 9999).'.yml';
             $filePath = $this->getDatadirBasePath() . '/bucket_root.yml';
             if (file_exists($filePath)) {
                 // This should never happen.
                 throw new RuntimeException('path for bucket alread exists: ' . $filePath);
             }
         }
         $bucket = new Bucket($filePath);
         $bucket->setDatadirBasePath($this->getDatadirBasePath());
         $bucket->setLocalNode($this->getLocalNode());
         $this->rootBucket = $bucket;
         $this->setDataChanged(true);
     }
     #$returnNode = $this->rootBucket->nodeEnclose($node);
     $returnNode = $this->rootBucket->nodeEnclose($node, false);
     return $returnNode;
 }
Esempio n. 3
0
 private function setChildBucketLower($distance)
 {
     if (!$this->childBucketLower) {
         list($newMaskByte, $newMaskBit, $newMaskBitValue) = $this->maskDecr();
         if ($newMaskByte < Node::ID_LEN_BYTE && $newMaskBitValue > 0) {
             $filePath = null;
             if ($this->getDatadirBasePath()) {
                 $filePath = $this->getDatadirBasePath() . '/bucket';
                 $filePath .= '_m' . sprintf('%02d', $newMaskByte) . '.' . $newMaskBit;
                 $filePath .= '_d' . sprintf('%03d', $distance);
                 $filePath .= '_l';
                 $filePath .= '.yml';
                 if (file_exists($filePath)) {
                     // This should never happen.
                     throw new RuntimeException('path for bucket alread exists: ' . $filePath);
                 }
             }
             $bucket = new Bucket($filePath);
             $bucket->setDistance($distance);
             $bucket->setMaskByte($newMaskByte);
             $bucket->setMaskBit($newMaskBit);
             $bucket->setIsLower(true);
             $bucket->setDatadirBasePath($this->getDatadirBasePath());
             $bucket->setLocalNode($this->getLocalNode());
             $bucket->setDataChanged(true);
             $this->childBucketLower = $bucket;
             $this->setDataChanged(true);
         }
         /*else{
         			$msgOut = 'mask is at the end: /'.$maskByte.'/ /'.intToBin($maskBitValue).'/ ('.$maskBitValue.')';
         			throw new RuntimeException('setChildBucketLower: '.$msgOut');
         			# NOT_IMPLEMENTED
         		}*/
     }
     /*else{
     			#$msgOut = intToBin($this->childBucketLower->getMaskBit()).' ('.$this->childBucketLower->getMaskBit().')';
     			#fwrite(STDOUT, 'upper is set: '.$msgOut."\n");
     		}*/
 }
Esempio n. 4
0
 /**
  * @group large
  */
 public function testNodeEnclose4()
 {
     #fwrite(STDOUT, 'testNodeEnclose4'.PHP_EOL);
     $runName = uniqid('', true);
     $fileName = 'testfile_table_table_' . date('Ymd_His') . '_' . $runName . '.yml';
     $NODES = 100;
     Bucket::$SIZE_MAX = 20;
     $localNode = new Node();
     $localNode->setIdHexStr('12000001-2002-4004-8008-100000000001');
     $table = new Table('test_data/' . $fileName);
     $table->setDatadirBasePath('test_data');
     $table->setLocalNode($localNode);
     $table->load();
     $nodeNoBegin = 100000000002;
     $nodeNoEnd = $nodeNoBegin + $NODES;
     for ($nodeNo = $nodeNoBegin; $nodeNo < $nodeNoEnd; $nodeNo++) {
         #fwrite(STDOUT, __METHOD__.' node setup: '.$nodeNo.''.PHP_EOL);
         timeStop('node setup ' . $nodeNo);
         $node = new Node();
         $node->setIdHexStr('12000001-2002-4004-8008-' . $nodeNo);
         $table->nodeEnclose($node);
     }
     fwrite(STDOUT, 'save' . PHP_EOL);
     $table->save();
     $nodeNum = $table->getNodesNum();
     fwrite(STDOUT, 'nodes: ' . $nodeNum . '' . PHP_EOL);
     #$this->assertEquals(160, $nodeNum);
     $this->assertTrue(true);
     $finder = new Finder();
     $files = $finder->in('test_data')->depth(0)->name('node_*.yml')->files();
     #$this->assertEquals(160, count($files));
     $this->clean();
 }