public function testReadingPhp() { $dbData = new dbDataProcessor(); $hashStep = dbWriter::HASH_STEP; $dbData->addCarrierInterval(new ipSegment(1, 4), "carrier1"); $dbData->addCarrierInterval(new ipSegment(2 * $hashStep, 3 * $hashStep - 1), "carrier2"); $opts = new optionsMock(); $dbStream = new dbStream(dirname(__FILE__) . "/tmp/test1.db", false); $dbWriter = new dbWriter($opts, $dbData, $dbStream); $dbWriter->writeDb(); $dbReader = new dbReader($dbStream); $dbReader->readAll(); $dbReader->checkConsistency(); $dbStream->close(); $dbCarrier = new CarrierDbPhp(dirname(__FILE__) . "/tmp/test1.db"); $info = $dbCarrier->getDbInfo(); $this->assertEquals(dbWriter::STRUCT_VERSION, $info['structVersion']); $this->assertEquals(1, $info['buildVersion']); $this->assertTrue(time() - $info['buildTimestamp'] < 10); // меньше 10 секунд назад $this->assertEquals(2, $info['recCount']); $this->assertEquals(NULL, $dbCarrier->get("0.0.0.0")); $this->assertEquals("carrier1", $dbCarrier->get("0.0.0.1")); $this->assertEquals("carrier1", $dbCarrier->get("0.0.0.2")); $this->assertEquals("carrier1", $dbCarrier->get("0.0.0.4")); $this->assertEquals(NULL, $dbCarrier->get("0.0.0.5")); $ipSeg = new ipSegment(floor(1.5 * $hashStep), floor(2.5 * $hashStep)); $this->assertEquals(NULL, $dbCarrier->get($ipSeg->getStartIpString())); $this->assertEquals("carrier2", $dbCarrier->get($ipSeg->getEndIpString())); $ipSeg = new ipSegment(3 * $hashStep - 1, 3 * $hashStep); $this->assertEquals("carrier2", $dbCarrier->get($ipSeg->getStartIpString())); $this->assertEquals(NULL, $dbCarrier->get($ipSeg->getEndIpString())); }
public function testReadWrite() { $fname = dirname(__FILE__) . "/tmp/test.db"; $dbStream = new dbStream($fname, false); $dbStream->write("test"); $this->assertEquals(4, $dbStream->tell()); $dbStream->seek(0); $this->assertEquals("test", $dbStream->read(4)); $dbStream->close(); $this->assertEquals(4, filesize($fname)); }
$carrierCsvWriter = new carrierCsvWriter($opts->outputCsv); $dbDataProcessor = new dbDataProcessor(); echo "INFO: Обработка данных\n"; $i = 0; while ($row = $collectorIterator->getNext()) { $carrierCsvWriter->addNext($row); $dbDataProcessor->addCarrierInterval($row['ipSeg'], $carrierCsvWriter->getCode($row)); $i++; if ($i % 1000 == 0) { echo "INFO: обработано {$i} записей\n"; } } unset($carrierCsvWriter); echo "INFO: Запись базы\n"; $dbStream = new dbStream($opts->outputDb, false); $dbWriter = new dbWriter($opts, $dbDataProcessor, $dbStream); $dbWriter->writeDb(); $dbStream->close(); unset($dbStream); unset($dbWriter); echo "INFO: Обновление версии\n"; $versionName = collectorOptions::VERSION_NAME; $opts->updateJsonFile($opts->{$versionName} + 1); $dbStream = new dbStream($opts->outputDb, true); echo "INFO: Проверка консистентности базы\n"; $dbReader = new dbReader($dbStream); $dbReader->readAll(); $dbReader->checkConsistency(); echo "INFO: В пике использовано " . memory_get_peak_usage() . "B\n"; $time2 = microtime(true); echo "INFO: Создание заняло " . ($time2 - $time1) . " сек";