TEST_F(CacheReaderTest, GetKeyShouldReturnCorrectKeyAfterRefresh) { auto catalogClient = Grid::get(operationContext())->catalogClient(operationContext()); KeysCollectionCacheReader reader("test", catalogClient); KeysCollectionDocument origKey1( 1, "test", TimeProofService::generateRandomKey(), LogicalTime(Timestamp(105, 0))); ASSERT_OK(insertToConfigCollection( operationContext(), NamespaceString(KeysCollectionDocument::ConfigNS), origKey1.toBSON())); auto refreshStatus = reader.refresh(operationContext()); ASSERT_OK(refreshStatus.getStatus()); { auto key = refreshStatus.getValue(); ASSERT_EQ(1, key.getKeyId()); ASSERT_EQ(origKey1.getKey(), key.getKey()); ASSERT_EQ("test", key.getPurpose()); ASSERT_EQ(Timestamp(105, 0), key.getExpiresAt().asTimestamp()); } auto status = reader.getKey(LogicalTime(Timestamp(1, 0))); ASSERT_OK(status.getStatus()); { auto key = status.getValue(); ASSERT_EQ(1, key.getKeyId()); ASSERT_EQ(origKey1.getKey(), key.getKey()); ASSERT_EQ("test", key.getPurpose()); ASSERT_EQ(Timestamp(105, 0), key.getExpiresAt().asTimestamp()); } }
TEST_F(CacheReaderTest, RefreshCanIncrementallyGetNewKeys) { auto catalogClient = Grid::get(operationContext())->catalogClient(operationContext()); KeysCollectionCacheReader reader("test", catalogClient); KeysCollectionDocument origKey0( 0, "test", TimeProofService::generateRandomKey(), LogicalTime(Timestamp(100, 0))); ASSERT_OK(insertToConfigCollection( operationContext(), NamespaceString(KeysCollectionDocument::ConfigNS), origKey0.toBSON())); { auto refreshStatus = reader.refresh(operationContext()); ASSERT_OK(refreshStatus.getStatus()); auto key = refreshStatus.getValue(); ASSERT_EQ(0, key.getKeyId()); ASSERT_EQ(origKey0.getKey(), key.getKey()); ASSERT_EQ("test", key.getPurpose()); ASSERT_EQ(Timestamp(100, 0), key.getExpiresAt().asTimestamp()); auto keyStatus = reader.getKey(LogicalTime(Timestamp(112, 1))); ASSERT_EQ(ErrorCodes::KeyNotFound, keyStatus.getStatus()); } KeysCollectionDocument origKey1( 1, "test", TimeProofService::generateRandomKey(), LogicalTime(Timestamp(105, 0))); ASSERT_OK(insertToConfigCollection( operationContext(), NamespaceString(KeysCollectionDocument::ConfigNS), origKey1.toBSON())); KeysCollectionDocument origKey2( 2, "test", TimeProofService::generateRandomKey(), LogicalTime(Timestamp(110, 0))); ASSERT_OK(insertToConfigCollection( operationContext(), NamespaceString(KeysCollectionDocument::ConfigNS), origKey2.toBSON())); { auto refreshStatus = reader.refresh(operationContext()); ASSERT_OK(refreshStatus.getStatus()); auto key = refreshStatus.getValue(); ASSERT_EQ(2, key.getKeyId()); ASSERT_EQ(origKey2.getKey(), key.getKey()); ASSERT_EQ("test", key.getPurpose()); ASSERT_EQ(Timestamp(110, 0), key.getExpiresAt().asTimestamp()); } { auto keyStatus = reader.getKey(LogicalTime(Timestamp(108, 1))); auto key = keyStatus.getValue(); ASSERT_EQ(2, key.getKeyId()); ASSERT_EQ(origKey2.getKey(), key.getKey()); ASSERT_EQ("test", key.getPurpose()); ASSERT_EQ(Timestamp(110, 0), key.getExpiresAt().asTimestamp()); } }
MSLane* MSEdge::parallelLane(const MSLane* const lane, int offset) const { const int index = (int)(find(myLanes->begin(), myLanes->end(), lane) - myLanes->begin()); if (index == (int)myLanes->size()) { return 0; } const int resultIndex = index + offset; if (resultIndex >= (int)myLanes->size() || resultIndex < 0) { // check for parallel running internal lanes if (getPurpose() == MSEdge::EDGEFUNCTION_INTERNAL) { const MSLane* pred = lane->getLogicalPredecessorLane(); const MSLane* next = lane->getLinkCont()[0]->getLane(); assert(pred != 0); assert(next != 0); const MSLane* predParallel = pred->getParallelLane(offset); const MSLane* nextParallel = next->getParallelLane(offset); if (predParallel != 0 && nextParallel != 0) { const MSLink* connecting = MSLinkContHelper::getConnectingLink(*predParallel, *nextParallel); if (connecting != 0) { return connecting->getViaLaneOrLane(); } } } return 0; } else { return (*myLanes)[resultIndex]; } }
Boundary GUIEdge::getBoundary() const { Boundary ret; if (getPurpose() != MSEdge::EDGEFUNCTION_DISTRICT) { for (std::vector<MSLane*>::const_iterator i = myLanes->begin(); i != myLanes->end(); ++i) { ret.add((*i)->getShape().getBoxBoundary()); } } else { // take the starting coordinates of all follower edges and the endpoints // of all successor edges for (MSEdgeVector::const_iterator it = mySuccessors.begin(); it != mySuccessors.end(); ++it) { const std::vector<MSLane*>& lanes = (*it)->getLanes(); for (std::vector<MSLane*>::const_iterator it_lane = lanes.begin(); it_lane != lanes.end(); ++it_lane) { ret.add((*it_lane)->getShape().front()); } } for (MSEdgeVector::const_iterator it = myPredecessors.begin(); it != myPredecessors.end(); ++it) { const std::vector<MSLane*>& lanes = (*it)->getLanes(); for (std::vector<MSLane*>::const_iterator it_lane = lanes.begin(); it_lane != lanes.end(); ++it_lane) { ret.add((*it_lane)->getShape().back()); } } } ret.grow(10); return ret; }
TEST_F(CacheReaderTest, RefreshShouldNotGetKeysForOtherPurpose) { auto catalogClient = Grid::get(operationContext())->catalogClient(operationContext()); KeysCollectionCacheReader reader("test", catalogClient); KeysCollectionDocument origKey0( 0, "dummy", TimeProofService::generateRandomKey(), LogicalTime(Timestamp(100, 0))); ASSERT_OK(insertToConfigCollection( operationContext(), NamespaceString(KeysCollectionDocument::ConfigNS), origKey0.toBSON())); { auto refreshStatus = reader.refresh(operationContext()); ASSERT_EQ(ErrorCodes::KeyNotFound, refreshStatus.getStatus()); auto emptyKeyStatus = reader.getKey(LogicalTime(Timestamp(50, 0))); ASSERT_EQ(ErrorCodes::KeyNotFound, emptyKeyStatus.getStatus()); } KeysCollectionDocument origKey1( 1, "test", TimeProofService::generateRandomKey(), LogicalTime(Timestamp(105, 0))); ASSERT_OK(insertToConfigCollection( operationContext(), NamespaceString(KeysCollectionDocument::ConfigNS), origKey1.toBSON())); { auto refreshStatus = reader.refresh(operationContext()); ASSERT_OK(refreshStatus.getStatus()); auto key = refreshStatus.getValue(); ASSERT_EQ(1, key.getKeyId()); ASSERT_EQ(origKey1.getKey(), key.getKey()); ASSERT_EQ("test", key.getPurpose()); ASSERT_EQ(Timestamp(105, 0), key.getExpiresAt().asTimestamp()); } auto keyStatus = reader.getKey(LogicalTime(Timestamp(60, 1))); ASSERT_OK(keyStatus.getStatus()); { auto key = keyStatus.getValue(); ASSERT_EQ(1, key.getKeyId()); ASSERT_EQ(origKey1.getKey(), key.getKey()); ASSERT_EQ("test", key.getPurpose()); ASSERT_EQ(Timestamp(105, 0), key.getExpiresAt().asTimestamp()); } }
TEST_F(CacheTest, GetKeyShouldReturnOldestKeyPossible) { KeysCollectionCache cache("test", catalogClient()); KeysCollectionDocument origKey0( 0, "test", TimeProofService::generateRandomKey(), LogicalTime(Timestamp(100, 0))); ASSERT_OK(insertToConfigCollection( operationContext(), KeysCollectionDocument::ConfigNS, origKey0.toBSON())); KeysCollectionDocument origKey1( 1, "test", TimeProofService::generateRandomKey(), LogicalTime(Timestamp(105, 0))); ASSERT_OK(insertToConfigCollection( operationContext(), KeysCollectionDocument::ConfigNS, origKey1.toBSON())); KeysCollectionDocument origKey2( 2, "test", TimeProofService::generateRandomKey(), LogicalTime(Timestamp(110, 0))); ASSERT_OK(insertToConfigCollection( operationContext(), KeysCollectionDocument::ConfigNS, origKey2.toBSON())); auto refreshStatus = cache.refresh(operationContext()); ASSERT_OK(refreshStatus.getStatus()); { auto key = refreshStatus.getValue(); ASSERT_EQ(2, key.getKeyId()); ASSERT_EQ(origKey2.getKey(), key.getKey()); ASSERT_EQ("test", key.getPurpose()); ASSERT_EQ(Timestamp(110, 0), key.getExpiresAt().asTimestamp()); } auto keyStatus = cache.getKey(LogicalTime(Timestamp(103, 1))); ASSERT_OK(keyStatus.getStatus()); { auto key = keyStatus.getValue(); ASSERT_EQ(1, key.getKeyId()); ASSERT_EQ(origKey1.getKey(), key.getKey()); ASSERT_EQ("test", key.getPurpose()); ASSERT_EQ(Timestamp(105, 0), key.getExpiresAt().asTimestamp()); } }
SUMOReal GUIEdge::getColorValue(size_t activeScheme) const { switch (activeScheme) { case 1: return gSelected.isSelected(getType(), getGlID()); case 2: return getPurpose(); case 3: return getAllowedSpeed(); case 4: return getBruttoOccupancy(); case 5: return getMeanSpeed(); case 6: return getFlow(); case 7: return getRelativeSpeed(); } return 0; }
TEST_F(CacheTest, GetKeyShouldReturnErrorIfNoKeyIsValidForGivenTime) { KeysCollectionCache cache("test", catalogClient()); KeysCollectionDocument origKey1( 1, "test", TimeProofService::generateRandomKey(), LogicalTime(Timestamp(105, 0))); ASSERT_OK(insertToConfigCollection( operationContext(), KeysCollectionDocument::ConfigNS, origKey1.toBSON())); auto refreshStatus = cache.refresh(operationContext()); ASSERT_OK(refreshStatus.getStatus()); { auto key = refreshStatus.getValue(); ASSERT_EQ(1, key.getKeyId()); ASSERT_EQ(origKey1.getKey(), key.getKey()); ASSERT_EQ("test", key.getPurpose()); ASSERT_EQ(Timestamp(105, 0), key.getExpiresAt().asTimestamp()); } auto status = cache.getKey(LogicalTime(Timestamp(110, 0))); ASSERT_EQ(ErrorCodes::KeyNotFound, status.getStatus()); }
SUMOReal GUIEdge::getColorValue(int activeScheme) const { switch (activeScheme) { case 1: return gSelected.isSelected(getType(), getGlID()); case 2: return getPurpose(); case 3: return getAllowedSpeed(); case 4: return getBruttoOccupancy(); case 5: return getMeanSpeed(); case 6: return getFlow(); case 7: return getRelativeSpeed(); case 8: return getRoutingSpeed(); case 16: return MSNet::getInstance()->getInsertionControl().getPendingEmits(getLanes()[0]); } return 0; }