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 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");
     		}*/
 }