/** * @depends testDiLog * @depends testDiCache */ public function testSplitCacheInterface() { $splitChanges = file_get_contents(__DIR__ . "/../../files/splitChanges.json"); $this->assertJson($splitChanges); $splitCache = new SplitCache(); $splitChanges = json_decode($splitChanges, true); $splits = $splitChanges['splits']; $split = $splits[0]; $splitName = $split['name']; $this->assertTrue($splitCache->addSplit($splitName, json_encode($split))); $this->assertEquals(strlen(json_encode($split)), strlen($splitCache->getSplit($splitName))); $this->assertTrue($splitCache->removeSplit($splitName)); $this->assertTrue($splitCache->setChangeNumber($splitChanges['till'])); $this->assertEquals($splitChanges['till'], $splitCache->getChangeNumber()); }
public function execute() { //Fetching the Splits changes $splitChanges = $this->getSplitClient()->getSplitChanges(); $splits = isset($splitChanges['splits']) ? $splitChanges['splits'] : array(); $splitCache = new SplitCache(); if (!empty($splits)) { foreach ($splits as $split) { if (!is_array($split) || !isset($split['name']) || !isset($split['conditions']) || !isset($split['status'])) { continue; //continue with next Split } $this->logger()->debug(print_r($split, true)); $splitName = $split['name']; $splitStatus = $split['status']; $splitConditions = $split['conditions']; foreach ($splitConditions as $condition) { foreach ($condition['matcherGroup']['matchers'] as $matcher) { if ($matcher['matcherType'] == "IN_SEGMENT") { //Register segment to retrieve Segment Data. SegmentCache::registerSegment($matcher['userDefinedSegmentMatcherData']['segmentName']); } } } if ($splitStatus == 'ACTIVE') { //Update Cache $splitCache->addSplit($splitName, json_encode($split)); } else { //Delete item from cache $splitCache->removeSplit($splitName); } } } if (isset($splitChanges['till'])) { $till = $splitChanges['till']; $this->logger()->debug("Splits Till value: {$till}"); //Updating next since (till) value. if ($till != $splitCache->getChangeNumber()) { $splitCache->setChangeNumber($till); } } }