public void ShouldFreeAndNotReuseCountersThatHaveCooldown() { int abc = _managerWithCooldown.Allocate("abc"); int def = _managerWithCooldown.Allocate("def"); int ghi = _managerWithCooldown.Allocate("ghi"); _managerWithCooldown.Free(def); _testClock.CurrentTimestamp += FREE_TO_REUSE_TIMEOUT - 1; Assert.That(_managerWithCooldown.Allocate("the next label"), Is.GreaterThan(ghi)); }
public static int AllocateCounterId( IMutableDirectBuffer tempBuffer, string name, int typeId, CountersManager countersManager, long registrationId) { tempBuffer.PutLong(REGISTRATION_ID_OFFSET, registrationId); int keyLength = REGISTRATION_ID_OFFSET + BitUtil.SIZE_OF_LONG; int labelLength = 0; labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, name); labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, ": "); labelLength += tempBuffer.PutLongAscii(keyLength + labelLength, registrationId); return(countersManager.Allocate(typeId, tempBuffer, 0, keyLength, tempBuffer, keyLength, labelLength)); }
public void ManagerShouldStoreLabels() { var counterId = _manager.Allocate("abc"); _otherManager.ForEach(_consumer); A.CallTo(() => _consumer(counterId, "abc")).MustHaveHappened(); }
public void ShouldTruncateLongLabel() { int labelLength = CountersReader.MAX_LABEL_LENGTH + 10; var sb = new StringBuilder(labelLength); for (int i = 0; i < labelLength; i++) { sb.Append('x'); } var label = sb.ToString(); int counterId = _manager.Allocate(label); _reader.ForEach(_consumer); A.CallTo(() => _consumer(counterId, label.Substring(0, CountersReader.MAX_LABEL_LENGTH))) .MustHaveHappened(); }