Beispiel #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());
 }
Beispiel #2
0
 private function setChildBucketUpper($distance)
 {
     if (!$this->childBucketUpper) {
         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 .= '_u';
                 $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->setIsUpper(true);
             $bucket->setDatadirBasePath($this->getDatadirBasePath());
             $bucket->setLocalNode($this->getLocalNode());
             $bucket->setDataChanged(true);
             $this->childBucketUpper = $bucket;
             $this->setDataChanged(true);
         }
         /*else{
         			$msgOut = 'mask is at the end: /'.$maskByte.'/ /'.intToBin($maskBitValue).'/ ('.$maskBitValue.')';
         			throw new RuntimeException('setChildBucketUpper: '.$msgOut);
         			# NOT_IMPLEMENTED
         		}*/
     }
     /*else{
     			#$msgOut = intToBin($this->childBucketUpper->getMaskBit()).' ('.$this->childBucketUpper->getMaskBit().')';
     			#fwrite(STDOUT, 'upper is set: '.$msgOut."\n");
     		}*/
 }