src_fm_fc_ms_ff stringlengths 43 86.8k | target stringlengths 20 276k |
|---|---|
DocumentFile { public String getInvariantStream() { return invariantStream; } private DocumentFile(); static org.oulipo.streams.Compiler<DocumentFile> compiler(); static Decompiler<DocumentFile> decompiler(); Map<Integer, String> get(); String getDocumentHash(); String getEncyptedInvariantStream(); String getGenesisHa... | @Test public void addText() throws Exception { DocumentFile.Builder builder = new DocumentFile.Builder("fakeHash"); builder.appendText("Xanadu"); builder.appendText("Green"); DocumentFile file = builder.build(); assertEquals("XanaduGreen", file.getInvariantStream()); } |
PutInvariantMediaOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (to ^ (to >>> 32)); return result; } PutInvariantMediaOp(DataInputStream dis); PutInvariantMediaOp(long to, int ripIndex); @Overrid... | @Test public void hashFalse() throws Exception { PutInvariantMediaOp op1 = new PutInvariantMediaOp(1, 2); PutInvariantMediaOp op2 = new PutInvariantMediaOp(2, 2); assertFalse(op1.hashCode() == op2.hashCode()); ; }
@Test public void hashTrue() throws Exception { PutInvariantMediaOp op1 = new PutInvariantMediaOp(1, 2); P... |
PutOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypes.size()... | @Test public void encodeDecode() throws Exception { PutOverlayOp op = new PutOverlayOp(new VariantSpan(100, 1), Sets.newSet(10, 5)); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.PUT_OVERLAY, dis.readByte()); PutOverlayOp decoded = new PutOverlayOp... |
VariantSpan { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; VariantSpan other = (VariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (!documentHash.equals(other.... | @Test public void homeNoMatch() throws Exception { assertFalse(new VariantSpan(1, 9, "fakeHash").equals(new VariantSpan(1, 10))); }
@Test public void startNoMatch() throws MalformedSpanException { assertFalse(new VariantSpan(1, 10).equals(new VariantSpan(2, 10))); }
@Test public void widthNoMatch() throws MalformedSpan... |
InvariantSpan implements Invariant { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; InvariantSpan other = (InvariantSpan) obj; if (documentHash == null) { if (other.documentHash != null) return false; } else if (... | @Test public void inequality() throws Exception { InvariantSpan s1 = new InvariantSpan(10, 60, "ted: InvariantSpan s2 = new InvariantSpan(10, 50, "ted: assertFalse(s1.equals(s2)); } |
InvariantSpan implements Invariant { @Override public StreamElementPartition<InvariantSpan> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IndexOutOfBoundsException( "Partition width must be greater than 0, partitionWidth = " + leftPartitionWidth); } if (width <= ... | @Test public void split() throws Exception { InvariantSpan span = new InvariantSpan(1, 4, documentHash); StreamElementPartition<InvariantSpan> result = span.split(1); assertEquals(new InvariantSpan(1, 1, documentHash), result.getLeft()); assertEquals(new InvariantSpan(2, 3, documentHash), result.getRight()); }
@Test pu... |
DocumentFile { public String getHashPreviousBlock() { return hashPreviousBlock; } private DocumentFile(); static org.oulipo.streams.Compiler<DocumentFile> compiler(); static Decompiler<DocumentFile> decompiler(); Map<Integer, String> get(); String getDocumentHash(); String getEncyptedInvariantStream(); String getGenes... | @Test public void hashBlock() throws Exception { DocumentFile.Builder builder = new DocumentFile.Builder("fakeHash"); builder.previousHashBlock("sadasdsad"); DocumentFile file = builder.build(); assertEquals("sadasdsad", file.getHashPreviousBlock()); } |
Node { public boolean isRoot() { return parent == null; } Node(long weight); Node(T value); long characterCount(); boolean isLeaf(); boolean isRightNode(); boolean isRoot(); Node<T> split(long leftPartitionWidth); @Override String toString(); public boolean isRed; public Node<T> left; public Node<T> parent; public Nod... | @Test public void root() throws Exception { assertTrue(new Node<InvariantSpan>(10).isRoot()); } |
Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartit... | @Test public void simpleSplit() throws Exception { Node<InvariantSpan> node = new Node<InvariantSpan>(new InvariantSpan(1, 10, documentHash)); Node<InvariantSpan> result = node.split(5); assertNotNull(result.left); assertNotNull(result.right); assertEquals(new InvariantSpan(1, 5, documentHash), result.left.value); asse... |
FileInvariantStream implements InvariantStream { @Override public InvariantSpan append(String text) throws IOException, MalformedSpanException { if (Strings.isNullOrEmpty(text)) { throw new MalformedSpanException("No text - span length is 0"); } FileLock lock = channel.lock(); try { InvariantSpan span = new InvariantSp... | @Test public void streamLoadable() throws Exception { File file = new File("target/streams-junit/FileInvariantStream-" + System.currentTimeMillis() + ".txt"); InvariantStream stream = new FileInvariantStream(file, null, "fakeHash", null); stream.append("Hello"); stream.append("Xanadu"); } |
DocumentFileCompiler implements Compiler<DocumentFile> { @Override public String compileEncrypted(DocumentFile doc, ECKey ecKey, Key key) throws Exception { if (ecKey == null) { throw new IllegalArgumentException("ECKey is null"); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream os = new Dat... | @Test public void addEncryptedTextCompile() throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); keyGen.initialize(2056); KeyPair pair = keyGen.generateKeyPair(); DocumentFile.Builder builder = new DocumentFile.Builder("fakeHash"); builder.appendEncryptedText("Xanadu"); builder.appendEncryp... |
Partitioner { public static <T extends StreamElement> NodePartition<T> createNodePartition(long leftPartitionWidth, Node<T> x) throws MalformedSpanException { if (x == null) { throw new IllegalStateException("Attempting to partition a null node"); } if (leftPartitionWidth < 0) { throw new IndexOutOfBoundsException( "Wi... | @Test public void createNodeParitionAlongRightCut() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 10, documentHash)); Node<InvariantSpan> right = new Node<>(new InvariantSpan(1, 20, documentHash)); Node<InvariantSpan> root = new Node.Builder<InvariantSpan>(10).left(left).right(right).bui... |
Partitioner { public static <S extends StreamElement> List<Node<S>> pruneIndexNode(Node<S> indexNode, long leftPartitionWidth, long displacement) { if (indexNode.isRightNode()) { if (indexNode.parent.parent != null) { if (indexNode.parent.left != null) { displacement -= indexNode.parent.left.weight; indexNode.parent.pa... | @Test public void createNodePartitionLinearList2() throws Exception { Node<InvariantSpan> a = new Node<>(new InvariantSpan(1, 1, documentHash)); Node<InvariantSpan> b = new Node<>(new InvariantSpan(2, 1, documentHash)); Node<InvariantSpan> c = new Node<>(new InvariantSpan(3, 1, documentHash)); Node<InvariantSpan> d = n... |
ToggleOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.TOGGLE_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypeIn... | @Test public void encodeDecode() throws Exception { ToggleOverlayOp op = new ToggleOverlayOp(new VariantSpan(100, 1), 10); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.TOGGLE_OVERLAY, dis.readByte()); ToggleOverlayOp decoded = new ToggleOverlayOp(... |
ApplyOverlayOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.APPLY_OVERLAY); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); dos.writeInt(linkTypes.si... | @Test public void encode() throws Exception { ApplyOverlayOp op = new ApplyOverlayOp(new VariantSpan(1, 100), Sets.newHashSet(1, 10)); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.APPLY_OVERLAY, dis.read()); assertEquals(1, dis.readLong()); assert... |
RopeVariantStream implements VariantStream<T> { @Override public void copy(long characterPosition, VariantSpan variantSpan) throws MalformedSpanException, IOException { putElements(characterPosition, getStreamElements(variantSpan)); } RopeVariantStream(String documentHash); RopeVariantStream(String documentHash, Node<... | @Test public void copy() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash, getA()); stream.copy(2, new VariantSpan(12, 3)); List<InvariantSpan> spans = stream.getStreamElements(); assertEquals(new InvariantSpan(100, 1, documentHash), spans.get(0)); assertEquals(new Invariant... |
RopeVariantStream implements VariantStream<T> { @Override public void delete(VariantSpan variantSpan) throws MalformedSpanException { if (variantSpan == null) { throw new MalformedSpanException("Variant span is null for delete operation"); } deleteRange(variantSpan); } RopeVariantStream(String documentHash); RopeVaria... | @Test public void delete() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash, getA()); stream.delete(new VariantSpan(12, 4)); List<InvariantSpan> spans = stream.getStreamElements(); assertEquals(new InvariantSpan(100, 6, documentHash), spans.get(0)); assertEquals(new Invarian... |
RopeVariantStream implements VariantStream<T> { @Override public List<T> getStreamElements() throws MalformedSpanException { List<T> elements = new ArrayList<>(); Iterator<Node<T>> it = getAllLeafNodes(); while (it.hasNext()) { Node<T> node = it.next(); if (node.value != null) { elements.add(node.value); } } return ele... | @Test public void getInvariantSpan() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash); List<InvariantSpan> spans = Arrays.asList(new InvariantSpan(1, 11, documentHash)); stream.putElements(1, spans); List<InvariantSpan> results = stream.getStreamElements(new VariantSpan(5, ... |
RopeVariantStream implements VariantStream<T> { @Override public List<VariantSpan> getVariantSpans(InvariantSpan targetSpan) throws MalformedSpanException { long index = 1; List<VariantSpan> vspans = new ArrayList<>(); List<T> spans = getStreamElements(); for (int i = 0; i < spans.size(); i++) { T element = spans.get(i... | @Test public void getVariantSpansTwoIntersect() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash); List<InvariantSpan> spans = Arrays.asList(new InvariantSpan(7, 5, documentHash), new InvariantSpan(4, 3, documentHash), new InvariantSpan(1, 3, documentHash)); stream.putElemen... |
RopeVariantStream implements VariantStream<T> { @Override public T index(long characterPosition) { if (root == null) { throw new IllegalStateException("Stream is empty"); } return RopeUtils.index(characterPosition, root, 0).node.value; } RopeVariantStream(String documentHash); RopeVariantStream(String documentHash, No... | @Test public void index() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash, getA()); InvariantSpan span = stream.index(12); assertEquals(new InvariantSpan(300, 4, documentHash), span); }
@Test public void index11() throws Exception { VariantStream<InvariantSpan> stream = new... |
RopeVariantStream implements VariantStream<T> { @Override public void put(long characterPosition, T val) throws MalformedSpanException { if (val == null) { throw new IllegalArgumentException("invariant span is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("put position must be greater than ... | @Test public void put() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash, getA()); stream.put(12, new InvariantSpan(500, 34, documentHash)); List<InvariantSpan> spans = stream.getStreamElements(); assertEquals(new InvariantSpan(100, 6, documentHash), spans.get(0)); assertEqu... |
RopeVariantStream implements VariantStream<T> { @Override public void swap(VariantSpan v1, VariantSpan v2) throws MalformedSpanException { Node<T> from = deleteRange(v1); from.parent = null; long startV2 = v2.start - v1.width; Node<T> to = deleteRange(new VariantSpan(startV2, v2.width)); to.parent = null; insert(v1.sta... | @Test public void swap() throws Exception { VariantStream<InvariantSpan> stream = new RopeVariantStream<>(documentHash, getA()); stream.swap(new VariantSpan(1, 3), new VariantSpan(12, 3)); List<InvariantSpan> spans = stream.getStreamElements(); assertEquals(new InvariantSpan(300, 3, documentHash), spans.get(0)); assert... |
SlotKeySerDes { protected static Granularity granularityFromSlotKey(String s) { String field = s.split(",", -1)[0]; for (Granularity g : Granularity.granularities()) if (g.name().startsWith(field)) return g; return null; } static SlotKey deserialize(String stateStr); String serialize(SlotKey slotKey); String serialize... | @Test public void testGranularityFromSlotKey() { Granularity expected = Granularity.MIN_5; Granularity myGranularity = SlotKeySerDes.granularityFromSlotKey(SlotKey.of(expected, 1, 1).toString()); Assert.assertNotNull(myGranularity); Assert.assertEquals(myGranularity, expected); myGranularity = SlotKeySerDes.granularity... |
LocatorFetchRunnable implements Runnable { protected Set<Locator> getLocators(RollupExecutionContext executionContext, boolean isReroll, Granularity delayedMetricsRerollGranularity, Granularity delayedMetricsStorageGranularity) { Set<Locator> locators = new HashSet<Locator>(); if (RECORD_DELAYED_METRICS && isReroll && ... | @Test public void testGetLocatorsForReRollLowerLevelToStorageGranularity() throws IOException { boolean isReroll = true; SlotKey destSlotKey = SlotKey.of(Granularity.MIN_5, 0, TEST_SHARD); Granularity delayedMetricsRerollGranularity = Granularity.MIN_60; Granularity delayedMetricsStorageGranularity = Granularity.MIN_20... |
Emitter { public Emitter once(final String event, final Listener<T> fn) { Listener on = new Listener<T>() { @Override public void call(T... args) { Emitter.this.off(event, this); fn.call(args); } }; this.onceCallbacks.put(fn, on); this.on(event, on); return this; } Emitter on(String event, Listener fn); Emitter once(f... | @Test public void testOnce() { emitter.once(testEventName, listener); emitter.emit(testEventName, new RollupEvent(null, null, "payload1", "gran", 0)); Assert.assertEquals(store.size(), 1); store.clear(); emitter.emit(testEventName, new RollupEvent(null, null, "payload1", "gran", 0)); Assert.assertEquals(store.size(), 0... |
Emitter { public Emitter on(String event, Listener fn) { ConcurrentLinkedQueue<Listener> callbacks = this.callbacks.get(event); if (callbacks == null) { callbacks = new ConcurrentLinkedQueue<Listener>(); ConcurrentLinkedQueue<Listener> _callbacks = this.callbacks.putIfAbsent(event, callbacks); if (_callbacks != null) {... | @Test public void testOn() { emitter.on(testEventName, listener); Assert.assertEquals(0, store.size()); emitter.emit(testEventName, event1); Assert.assertEquals(1, store.size()); Assert.assertSame(event1, store.get(0)); emitter.emit(testEventName, event2); Assert.assertEquals(2, store.size()); Assert.assertSame(event1,... |
RollupEvent { public Locator getLocator() { return locator; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); Rollup getRollup(); Locator getLocator(); String getUnit(); String getGranularityName(); long getTimestamp(); void setUnit(String unit); } | @Test public void locatorGetsSetInConstructor() { Assert.assertSame(locator, event.getLocator()); } |
RollupEvent { public Rollup getRollup() { return rollup; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); Rollup getRollup(); Locator getLocator(); String getUnit(); String getGranularityName(); long getTimestamp(); void setUnit(String unit); } | @Test public void rollupGetsSetInConstructor() { Assert.assertSame(rollup, event.getRollup()); } |
RollupEvent { public String getUnit() { return unit; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); Rollup getRollup(); Locator getLocator(); String getUnit(); String getGranularityName(); long getTimestamp(); void setUnit(String unit); } | @Test public void unitGetsSetInConstructor() { Assert.assertEquals(unit, event.getUnit()); } |
RollupEvent { public String getGranularityName() { return granularityName; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); Rollup getRollup(); Locator getLocator(); String getUnit(); String getGranularityName(); long getTimestamp(); void setUnit(String unit); } | @Test public void granularityGetsSetInConstructor() { Assert.assertEquals(granularity, event.getGranularityName()); } |
RetryNTimes implements RetryPolicy { @Override public RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl, WriteType wt, int requiredResponses, int receivedResponses, int wTime) { if (wTime < writeAttempts) { LOG.info(String.format("Retrying on WriteTimeout: stmnt %s, " + "consistency %s, writeType %s, re... | @Test public void firstTimeRetryOnWriteTimeout_shouldRetry() throws Exception { RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3); Statement mockStatement = mock( Statement.class ); RetryPolicy.RetryDecision retryResult = retryPolicy.onWriteTimeout(mockStatement, ConsistencyLevel.LOCAL_ONE, WriteType.BATCH, 1, 0, 0); ... |
RollupEvent { public long getTimestamp() { return timestamp; } RollupEvent(Locator loc, Rollup rollup, String unit, String gran, long ts); Rollup getRollup(); Locator getLocator(); String getUnit(); String getGranularityName(); long getTimestamp(); void setUnit(String unit); } | @Test public void timestampGetsSetInConstructor() { Assert.assertEquals(timestamp, event.getTimestamp()); } |
RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Overrid... | @Test public void testConcurrentEmission() throws InterruptedException, ExecutionException { emitter.on(testEventName, listener); ThreadPoolExecutor executors = new ThreadPoolBuilder() .withCorePoolSize(2) .withMaxPoolSize(3) .build(); final CountDownLatch startLatch = new CountDownLatch(1); Future<Object> f1 = executo... |
Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf... | @Test public void testForCloseness() { int desiredPoints = 10; long start = Calendar.getInstance().getTimeInMillis(); Assert.assertEquals(Granularity.MIN_20, Granularity.granularityFromPointsInInterval("TENANTID1234",start, start + 10000000, desiredPoints)); Assert.assertEquals(Granularity.MIN_5, Granularity.granularit... |
Granularity { public Granularity coarser() throws GranularityException { if (this == LAST) throw new GranularityException("Nothing coarser than " + name()); return granularities[index + 1]; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int millis... | @Test public void coarserReturnsCoarser() throws GranularityException { Assert.assertSame(Granularity.MIN_5, Granularity.FULL.coarser()); Assert.assertSame(Granularity.MIN_20, Granularity.MIN_5.coarser()); Assert.assertSame(Granularity.MIN_60, Granularity.MIN_20.coarser()); Assert.assertSame(Granularity.MIN_240, Granul... |
Granularity { public Granularity finer() throws GranularityException { if (this == FULL) throw new GranularityException("Nothing finer than " + name()); return granularities[index - 1]; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int millisecon... | @Test public void finerReturnsFiner() throws GranularityException { Assert.assertSame(Granularity.FULL, Granularity.MIN_5.finer()); Assert.assertSame(Granularity.MIN_5, Granularity.MIN_20.finer()); Assert.assertSame(Granularity.MIN_20, Granularity.MIN_60.finer()); Assert.assertSame(Granularity.MIN_60, Granularity.MIN_2... |
RetryNTimes implements RetryPolicy { @Override public RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl, int requiredResponses, int receivedResponses, int uTime) { if (uTime < unavailableAttempts) { LOG.info(String.format("Retrying on unavailable: stmnt %s, consistency %s, " + "requiredResponse %d, recei... | @Test public void firstTimeRetryOnUnavailable_shouldRetry() throws Exception { RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3); Statement mockStatement = mock( Statement.class ); RetryPolicy.RetryDecision retryResult = retryPolicy.onUnavailable(mockStatement, ConsistencyLevel.LOCAL_ONE, 1, 0, 0); RetryPolicy.RetryDe... |
Granularity { @Override public boolean equals(Object obj) { if (!(obj instanceof Granularity)) return false; else return obj == this; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granula... | @Test public void equalsWithSameValueReturnsTrue() { Assert.assertTrue(Granularity.FULL.equals(Granularity.FULL)); Assert.assertTrue(Granularity.MIN_5.equals(Granularity.MIN_5)); Assert.assertTrue(Granularity.MIN_20.equals(Granularity.MIN_20)); Assert.assertTrue(Granularity.MIN_60.equals(Granularity.MIN_60)); Assert.as... |
Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int num... | @Test public void fromStringFull() { String s = "metrics_full"; Granularity gran = Granularity.fromString(s); Assert.assertNotNull(gran); Assert.assertSame(Granularity.FULL, gran); }
@Test public void fromString5m() { String s = "metrics_5m"; Granularity gran = Granularity.fromString(s); Assert.assertNotNull(gran); Ass... |
RollupTypeCacher extends FunctionWithThreadPool<MetricsCollection, Void> { @Override public Void apply(final MetricsCollection input) throws Exception { getThreadPool().submit(new Runnable() { @Override public void run() { recordWithTimer(input); } }); return null; } RollupTypeCacher(ThreadPoolExecutor executor, Metada... | @Test public void testCacher() throws Exception { MetricsCollection collection = createTestData(); MetadataCache rollupTypeCache = mock(MetadataCache.class); ThreadPoolExecutor tpe = new ThreadPoolBuilder().withName("rtc test").build(); RollupTypeCacher rollupTypeCacher = new RollupTypeCacher(tpe, rollupTypeCache); rol... |
Granularity { public boolean isCoarser(Granularity other) { return indexOf(this) > indexOf(other); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Gra... | @Test public void coarserGranularitiesAreCoarserThanFinerOnes() { Assert.assertFalse(Granularity.FULL.isCoarser(Granularity.MIN_5)); Assert.assertFalse(Granularity.MIN_5.isCoarser(Granularity.MIN_20)); Assert.assertFalse(Granularity.MIN_20.isCoarser(Granularity.MIN_60)); Assert.assertFalse(Granularity.MIN_60.isCoarser(... |
Granularity { public long snapMillis(long millis) { if (this == FULL) return millis; else return (millis / milliseconds) * milliseconds; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Gran... | @Test public void snapMillisOnFullReturnsSameValue() { Assert.assertEquals(1234L, Granularity.FULL.snapMillis(1234L)); Assert.assertEquals(1000L, Granularity.FULL.snapMillis(1000L)); Assert.assertEquals(0L, Granularity.FULL.snapMillis(0L)); Assert.assertEquals(1234567L, Granularity.FULL.snapMillis(1234567L)); }
@Test p... |
Granularity { static int millisToSlot(long millis) { return (int)((millis % (BASE_SLOTS_PER_GRANULARITY * MILLISECONDS_IN_SLOT)) / MILLISECONDS_IN_SLOT); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularit... | @Test public void millisToSlotReturnsNumberOfSlotForGivenTime() { Assert.assertEquals(0, Granularity.millisToSlot(0)); Assert.assertEquals(0, Granularity.millisToSlot(1)); Assert.assertEquals(0, Granularity.millisToSlot(299999L)); Assert.assertEquals(1, Granularity.millisToSlot(300000L)); Assert.assertEquals(1, Granula... |
Granularity { public int slot(long millis) { int fullSlot = millisToSlot(millis); return (numSlots * fullSlot) / BASE_SLOTS_PER_GRANULARITY; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); ... | @Test public void slotReturnsTheSlotNumber() { Assert.assertEquals(0, Granularity.FULL.slot(1234L)); Assert.assertEquals(0, Granularity.FULL.slot(1000L)); Assert.assertEquals(0, Granularity.FULL.slot(0L)); Assert.assertEquals(0, Granularity.FULL.slot(299999L)); Assert.assertEquals(1, Granularity.FULL.slot(300000L)); As... |
TypeAndUnitProcessor extends FunctionWithThreadPool<MetricsCollection, Void> { @Override public Void apply(final MetricsCollection input) throws Exception { getThreadPool().submit(new Callable<MetricsCollection>() { public MetricsCollection call() throws Exception { Collection<IncomingMetricException> problems = metric... | @Test public void test() throws Exception { MetricsCollection collection = createTestData(); IncomingMetricMetadataAnalyzer metricMetadataAnalyzer = mock(IncomingMetricMetadataAnalyzer.class); ThreadPoolExecutor tpe = new ThreadPoolBuilder().withName("rtc test").build(); TypeAndUnitProcessor typeAndUnitProcessor = new ... |
Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(r... | @Test public void deriveRangeFiveMinuteFirstSlot() { Granularity gran = Granularity.MIN_5; Range range; range = gran.deriveRange(0, 0); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(299999, range.getStop()); range = gran.deriveRange(0, 1); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(29... |
BatchWriter extends FunctionWithThreadPool<List<List<IMetric>>, ListenableFuture<List<Boolean>>> { @Override public ListenableFuture<List<Boolean>> apply(List<List<IMetric>> input) throws Exception { final long writeStartTime = System.currentTimeMillis(); final Timer.Context actualWriteCtx = writeDurationTimer.time(); ... | @Test public void testWriter() throws Exception { Counter bufferedMetrics = mock(Counter.class); IngestionContext context = mock(IngestionContext.class); AbstractMetricsRW basicRW = mock(AbstractMetricsRW.class); AbstractMetricsRW preAggrRW = mock(AbstractMetricsRW.class); MetricsRWDelegator metricsRWDelegator = new Me... |
Granularity { public int slotFromFinerSlot(int finerSlot) throws GranularityException { return (finerSlot * numSlots()) / this.finer().numSlots(); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coars... | @Test public void slotFromFiner() throws GranularityException { Assert.assertEquals(0, Granularity.MIN_5.slotFromFinerSlot(0)); Assert.assertEquals(1, Granularity.MIN_5.slotFromFinerSlot(1)); Assert.assertEquals(4031, Granularity.MIN_5.slotFromFinerSlot(4031)); Assert.assertEquals(4032, Granularity.MIN_5.slotFromFinerS... |
RollupService implements Runnable, RollupServiceMBean { final void poll() { Timer.Context timer = polltimer.time(); context.scheduleEligibleSlots(rollupDelayMillis, rollupDelayForMetricsWithShortDelay, rollupWaitForMetricsWithLongDelay); timer.stop(); } RollupService(ScheduleContext context); @VisibleForTesting Rollup... | @Test public void pollSchedulesEligibleSlots() { service.poll(); verify(context).scheduleEligibleSlots(anyLong(), anyLong(), anyLong()); verifyNoMoreInteractions(context); verifyZeroInteractions(shardStateManager); verifyZeroInteractions(locatorFetchExecutors); verifyZeroInteractions(rollupReadExecutors); verifyZeroInt... |
SlotKey { public SlotKey extrapolate(Granularity destGranularity) { if (destGranularity.equals(this.getGranularity())) { return this; } if (!destGranularity.isCoarser(getGranularity())) { throw new IllegalArgumentException("Destination granularity must be coarser than the current granularity"); } int factor = getGranul... | @Test public void testExtrapolate() { int shard = 1; assertEquals("Invalid extrapolation - scenario 0", SlotKey.of(Granularity.MIN_5, 1, shard), SlotKey.of(Granularity.FULL, 1, shard).extrapolate(Granularity.MIN_5)); assertEquals("Invalid extrapolation - scenario 1", SlotKey.of(Granularity.MIN_5, 43, shard), SlotKey.of... |
ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null... | @Test public void singleClassYieldsThatClass() { Configuration.getInstance().setProperty( CoreConfig.DISCOVERY_MODULES, "com.rackspacecloud.blueflood.utils.DummyDiscoveryIO3"); Object loadedModule = ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Assert.assertNotNull(loadedModule); Assert.ass... |
RollupService implements Runnable, RollupServiceMBean { public synchronized void setServerTime(long millis) { log.info("Manually setting server time to {} {}", millis, new java.util.Date(millis)); context.setCurrentTimeMillis(millis); } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleC... | @Test public void setServerTimeSetsContextTime() { service.setServerTime(1234L); verify(context).setCurrentTimeMillis(anyLong()); verifyNoMoreInteractions(context); verifyZeroInteractions(shardStateManager); verifyZeroInteractions(locatorFetchExecutors); verifyZeroInteractions(rollupReadExecutors); verifyZeroInteractio... |
SlotKeySerDes { protected static int slotFromSlotKey(String s) { return Integer.parseInt(s.split(",", -1)[1]); } static SlotKey deserialize(String stateStr); String serialize(SlotKey slotKey); String serialize(Granularity gran, int slot, int shard); } | @Test public void testSlotFromSlotKey() { int expectedSlot = 1; int slot = SlotKeySerDes.slotFromSlotKey(SlotKey.of(Granularity.MIN_5, expectedSlot, 10).toString()); Assert.assertEquals(expectedSlot, slot); } |
GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } | @Test public void testGlobMatchingAnyChar() { String glob = "*"; String expectedRegex = ".*"; GlobPattern pattern = new GlobPattern(glob); Assert.assertEquals(expectedRegex, pattern.compiled().toString()); }
@Test public void testEmptyGlob() { String glob = ""; String expectedRegex = ""; GlobPattern pattern = new GlobP... |
RollupService implements Runnable, RollupServiceMBean { public synchronized long getServerTime() { return context.getCurrentTimeMillis(); } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
... | @Test public void getServerTimeGetsContextTime() { long expected = 1234L; doReturn(expected).when(context).getCurrentTimeMillis(); long actual = service.getServerTime(); assertEquals(expected, actual); verify(context).getCurrentTimeMillis(); verifyNoMoreInteractions(context); verifyZeroInteractions(shardStateManager); ... |
SafetyTtlProvider implements TenantTtlProvider { @Override public Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType) { return getSafeTTL(gran, rollupType); } SafetyTtlProvider(); @Override Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType); Optional<Ti... | @Test public void testAlwaysPresent() { Assert.assertTrue(ttlProvider.getTTL("test", Granularity.FULL, RollupType.NOT_A_ROLLUP).isPresent()); } |
LocatorCache { public synchronized void setLocatorCurrentInBatchLayer(Locator loc) { getOrCreateInsertedLocatorEntry(loc).setBatchCurrent(); } protected LocatorCache(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTi... | @Test public void testSetLocatorCurrentInBatchLayer() throws InterruptedException { locatorCache.setLocatorCurrentInBatchLayer(LOCATOR); assertTrue("locator not stored in cache", locatorCache.isLocatorCurrentInBatchLayer(LOCATOR)); Thread.sleep(2000L); assertTrue("locator not expired from cache", !locatorCache.isLocato... |
LocatorCache { public synchronized boolean isLocatorCurrentInBatchLayer(Locator loc) { LocatorCacheEntry entry = insertedLocators.getIfPresent(loc.toString()); return entry != null && entry.isBatchCurrent(); } protected LocatorCache(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
... | @Test public void testIsLocatorCurrentInBatchLayer() throws InterruptedException { assertTrue("locator which was never set is present in cache", !locatorCache.isLocatorCurrentInBatchLayer(LOCATOR)); locatorCache.setLocatorCurrentInBatchLayer(LOCATOR); assertTrue("locator not stored in cache", locatorCache.isLocatorCurr... |
LocatorCache { public synchronized void setLocatorCurrentInDiscoveryLayer(Locator loc) { getOrCreateInsertedLocatorEntry(loc).setDiscoveryCurrent(); } protected LocatorCache(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfte... | @Test public void testSetLocatorCurrentInDiscoveryLayer() throws InterruptedException { locatorCache.setLocatorCurrentInDiscoveryLayer(LOCATOR); assertTrue("locator not stored in cache", locatorCache.isLocatorCurrentInDiscoveryLayer(LOCATOR)); Thread.sleep(2000L); assertTrue("locator not expired from cache", !locatorCa... |
LocatorCache { public synchronized boolean isLocatorCurrentInDiscoveryLayer(Locator loc) { LocatorCacheEntry entry = insertedLocators.getIfPresent(loc.toString()); return entry != null && entry.isDiscoveryCurrent(); } protected LocatorCache(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
... | @Test public void testIsLocatorCurrentInDiscoveryLayer() throws InterruptedException { assertTrue("locator which was never set is present in cache", !locatorCache.isLocatorCurrentInDiscoveryLayer(LOCATOR)); locatorCache.setLocatorCurrentInDiscoveryLayer(LOCATOR); assertTrue("locator not stored in cache", locatorCache.i... |
RollupService implements Runnable, RollupServiceMBean { public synchronized boolean getKeepingServerTime() { return keepingServerTime; } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
... | @Test public void getKeepingServerTimeGetsKeepingServerTime() { assertEquals(true, service.getKeepingServerTime()); } |
ConfigTtlProvider implements TenantTtlProvider { @Override public Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType) { final TimeValue ttl = ttlMapper.get(gran, rollupType); if (ttl == null) { log.trace("No valid TTL entry for granularity: {}, rollup type: {}" + " in config. Resorting ... | @Test public void testConfigTtl_invalid() { Assert.assertFalse(ttlProvider.getTTL("acBar", Granularity.FULL, RollupType.SET).isPresent()); } |
CombinedTtlProvider implements TenantTtlProvider { @Override public Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType) { Optional<TimeValue> primaryValue = primary.getTTL(tenantId, gran, rollupType); Optional<TimeValue> safetyValue = safety.getTTL(tenantId, gran, rollupType); return ge... | @Test public void testGetTTL() throws Exception { assertTrue(combinedProvider.getTTL("foo", Granularity.FULL, RollupType.BF_BASIC).isPresent()); assertTrue(combinedProvider.getTTL("foo", Granularity.MIN_5, RollupType.BF_BASIC).isPresent()); assertFalse(configProvider.getTTL("foo", Granularity.MIN_5, RollupType.BF_BASIC... |
Metric implements IMetric { public void setTtl(TimeValue ttl) { if (!isValidTTL(ttl.toSeconds())) { throw new InvalidDataException("TTL supplied for metric is invalid. Required: 0 < ttl < " + Integer.MAX_VALUE + ", provided: " + ttl.toSeconds()); } ttlInSeconds = (int) ttl.toSeconds(); } Metric(Locator locator, Object ... | @Test public void testTTL() { Locator locator = Locator.createLocatorFromPathComponents("tenantId", "metricName"); Metric metric = new Metric(locator, 134891734L, System.currentTimeMillis(), new TimeValue(5, TimeUnit.HOURS), "Unknown"); try { metric.setTtl(new TimeValue(Long.MAX_VALUE, TimeUnit.SECONDS)); fail(); } cat... |
Locator implements Comparable<Locator> { public String toString() { return stringRep; } Locator(); private Locator(String fullyQualifiedMetricName); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); String getTenantId(); String getMetricName(); boolean equals(Locator other); static Loc... | @Test public void publicConstructorDoesNotSetStringRepresentation() { Locator locator = new Locator(); assertNotNull(locator); assertNull(locator.toString()); } |
Locator implements Comparable<Locator> { public String getTenantId() { return this.tenantId; } Locator(); private Locator(String fullyQualifiedMetricName); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); String getTenantId(); String getMetricName(); boolean equals(Locator other); sta... | @Test public void publicConstructorDoesNotSetTenant() { Locator locator = new Locator(); assertNotNull(locator); assertNull(locator.getTenantId()); } |
Locator implements Comparable<Locator> { public String getMetricName() { return this.metricName; } Locator(); private Locator(String fullyQualifiedMetricName); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); String getTenantId(); String getMetricName(); boolean equals(Locator other);... | @Test public void publicConstructorDoesNotSetMetricName() { Locator locator = new Locator(); assertNotNull(locator); assertNull(locator.getMetricName()); } |
Locator implements Comparable<Locator> { protected boolean isValidDBKey(String dbKey, String delim) { return dbKey.contains(delim); } Locator(); private Locator(String fullyQualifiedMetricName); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); String getTenantId(); String getMetricNam... | @Test(expected = NullPointerException.class) public void isValidDBKeyThrowsExceptionOnNullDbKey() { Locator locator = new Locator(); locator.isValidDBKey(null, "a"); }
@Test(expected = NullPointerException.class) public void isValidDBKeyThrowsExceptionOnNullDelim() { Locator locator = new Locator(); locator.isValidDBKe... |
RollupService implements Runnable, RollupServiceMBean { public synchronized long getPollerPeriod() { return pollerPeriod; } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
ThreadPool... | @Test public void getPollerPeriodGetsPollerPeriod() { assertEquals(0, service.getPollerPeriod()); } |
Locator implements Comparable<Locator> { @Override public int hashCode() { return stringRep == null ? 0 : stringRep.hashCode(); } Locator(); private Locator(String fullyQualifiedMetricName); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); String getTenantId(); String getMetricName();... | @Test public void hashCodeNullReturnsZero() { Locator locator = new Locator(); assertEquals(0, locator.hashCode()); } |
Locator implements Comparable<Locator> { @Override public boolean equals(Object obj) { return obj != null && obj instanceof Locator && obj.hashCode() == this.hashCode(); } Locator(); private Locator(String fullyQualifiedMetricName); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); Str... | @Test public void equalsNullReturnsFalse() { Locator locator = new Locator(); assertFalse(locator.equals((Object)null)); }
@Test public void equalsNonLocatorReturnsFalse() { Locator locator = new Locator(); assertFalse(locator.equals(new Object())); }
@Test public void equalsBothUninitializedReturnsTrue() { Locator loc... |
Points { public Class getDataClass() { if (points.size() == 0) throw new IllegalStateException(""); return points.values().iterator().next().data.getClass(); } Points(); void add(Point<T> point); Map<Long, Point<T>> getPoints(); boolean isEmpty(); Class getDataClass(); } | @Test(expected=IllegalStateException.class) public void getDataClassOnEmptyObjectThrowsException() { Points<SimpleNumber> points = new Points<SimpleNumber>(); Class actual = points.getDataClass(); } |
AbstractRollupStat { public boolean isFloatingPoint() { return this.isFloatingPoint; } AbstractRollupStat(); boolean isFloatingPoint(); double toDouble(); long toLong(); @Override boolean equals(Object otherObject); void setLongValue(long value); void setDoubleValue(double value); abstract byte getStatType(); String to... | @Test public void newlyCreatedObjectIsNotFloatingPoint() { SimpleStat stat = new SimpleStat(); assertFalse(stat.isFloatingPoint()); } |
RollupService implements Runnable, RollupServiceMBean { public synchronized int getScheduledSlotCheckCount() { return context.getScheduledCount(); } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
... | @Test public void getScheduledSlotCheckCountGetsCount() { int expected = 3; doReturn(expected).when(context).getScheduledCount(); int actual = service.getScheduledSlotCheckCount(); assertEquals(expected, actual); verify(context).getScheduledCount(); verifyNoMoreInteractions(context); } |
AbstractRollupStat { @Override public boolean equals(Object otherObject) { if (!(otherObject instanceof AbstractRollupStat)) { return false; } AbstractRollupStat other = (AbstractRollupStat)otherObject; if (this.isFloatingPoint != other.isFloatingPoint()) { return false; } if (this.isFloatingPoint) { return this.toDoub... | @Test public void statsAreEqualIfTheirLongNumericalValuesAreEqual() { SimpleStat a = new SimpleStat(123L); SimpleStat b = new SimpleStat(123L); assertTrue(a.equals(b)); assertTrue(b.equals(a)); }
@Test public void statsAreNotEqualIfTheirLongNumericalValuesAreNotEqual() { SimpleStat a = new SimpleStat(123L); SimpleStat ... |
RollupService implements Runnable, RollupServiceMBean { public synchronized int getSlotCheckConcurrency() { return locatorFetchExecutors.getMaximumPoolSize(); } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager... | @Test public void testGetSlotCheckConcurrency() { int expected = 12; doReturn(expected).when(locatorFetchExecutors).getMaximumPoolSize(); int actual = service.getSlotCheckConcurrency(); assertEquals(expected, actual); verify(locatorFetchExecutors).getMaximumPoolSize(); verifyNoMoreInteractions(locatorFetchExecutors); } |
BasicRollup extends BaseRollup implements IBaseRollup { public static BasicRollup buildRollupFromRawSamples(Points<SimpleNumber> input) throws IOException { final BasicRollup basicRollup = new BasicRollup(); basicRollup.computeFromSimpleMetrics(input); return basicRollup; } BasicRollup(); @Override boolean equals(Objec... | @Test public void buildRollupFromRawSamples() throws IOException { BasicRollup rollup = createFromPoints( 5 ); assertEquals( "count is equal", 5, rollup.getCount() ); assertEquals( "average is equal", 30L, rollup.getAverage().toLong() ); assertEquals( "variance is equal", 200, rollup.getVariance().toDouble(), EPSILON )... |
BasicRollup extends BaseRollup implements IBaseRollup { public static BasicRollup buildRollupFromRollups(Points<BasicRollup> input) throws IOException { final BasicRollup basicRollup = new BasicRollup(); basicRollup.computeFromRollups(input); return basicRollup; } BasicRollup(); @Override boolean equals(Object other); ... | @Test public void buildRollupFromRollups() throws IOException { Points<BasicRollup> rollups = new Points<BasicRollup>() {{ add( new Points.Point<BasicRollup>( 1, createFromPoints( 1 ) ) ); add( new Points.Point<BasicRollup>( 2, createFromPoints( 2 ) ) ); add( new Points.Point<BasicRollup>( 3, createFromPoints( 3 ) ) );... |
MinValue extends AbstractRollupStat { @Override void handleFullResMetric(Object o) throws RuntimeException { if (o instanceof Double) { if (init) { this.setDoubleValue((Double)o); this.init = false; return; } if (!this.isFloatingPoint()) { if ((double)this.toLong() > (Double)o) { this.setDoubleValue((Double)o); } } els... | @Test public void fullResInitialDoubleSetsValue() { min.handleFullResMetric(123.45d); assertTrue(min.isFloatingPoint()); assertEquals(123.45d, min.toDouble(), 0.00001d); }
@Test public void fullResInitialLongSetsValue() { min.handleFullResMetric(123L); assertFalse(min.isFloatingPoint()); assertEquals(123L, min.toLong()... |
RollupService implements Runnable, RollupServiceMBean { public synchronized void setSlotCheckConcurrency(int i) { locatorFetchExecutors.setCorePoolSize(i); locatorFetchExecutors.setMaximumPoolSize(i); } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
... | @Test public void testSetSlotCheckConcurrency() { service.setSlotCheckConcurrency(3); verify(locatorFetchExecutors).setCorePoolSize(anyInt()); verify(locatorFetchExecutors).setMaximumPoolSize(anyInt()); verifyNoMoreInteractions(locatorFetchExecutors); } |
MinValue extends AbstractRollupStat { @Override void handleRollupMetric(IBaseRollup baseRollup) throws RuntimeException { AbstractRollupStat other = baseRollup.getMinValue(); if (init) { if (other.isFloatingPoint()) { this.setDoubleValue(other.toDouble()); } else { this.setLongValue(other.toLong()); } init = false; ret... | @Test public void rollupInitialFloatingPointSetsValue() { double value = 123.45d; IBaseRollup rollup = mock(IBaseRollup.class); MinValue other = new MinValue(value); doReturn(other).when(rollup).getMinValue(); min.handleRollupMetric(rollup); assertTrue(min.isFloatingPoint()); assertEquals(value, min.toDouble(), 0.00001... |
RollupService implements Runnable, RollupServiceMBean { public synchronized int getRollupConcurrency() { return rollupReadExecutors.getMaximumPoolSize(); } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
... | @Test public void testGetRollupConcurrency() { int expected = 12; doReturn(expected).when(rollupReadExecutors).getMaximumPoolSize(); int actual = service.getRollupConcurrency(); assertEquals(expected, actual); verify(rollupReadExecutors).getMaximumPoolSize(); verifyNoMoreInteractions(rollupReadExecutors); } |
MinValue extends AbstractRollupStat { @Override public byte getStatType() { return Constants.MIN; } MinValue(); @SuppressWarnings("unused") // used by Jackson MinValue(long value); @SuppressWarnings("unused") // used by Jackson MinValue(double value); @Override byte getStatType(); } | @Test public void returnsTheCorrectStatType() { assertEquals(Constants.MIN, min.getStatType()); } |
MaxValue extends AbstractRollupStat { @Override void handleFullResMetric(Object o) throws RuntimeException { if (o instanceof Double) { if (init) { this.setDoubleValue((Double)o); this.init = false; return; } if (!this.isFloatingPoint()) { if ((double)this.toLong() < (Double)o) { this.setDoubleValue((Double)o); } } els... | @Test public void fullResInitialDoubleSetsValue() { max.handleFullResMetric(123.45d); assertTrue(max.isFloatingPoint()); assertEquals(123.45d, max.toDouble(), 0.00001d); }
@Test public void fullResInitialLongSetsValue() { max.handleFullResMetric(123L); assertFalse(max.isFloatingPoint()); assertEquals(123L, max.toLong()... |
RollupService implements Runnable, RollupServiceMBean { public synchronized void setRollupConcurrency(int i) { rollupReadExecutors.setCorePoolSize(i); rollupReadExecutors.setMaximumPoolSize(i); } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
... | @Test public void testSetRollupConcurrency() { service.setRollupConcurrency(3); verify(rollupReadExecutors).setCorePoolSize(anyInt()); verify(rollupReadExecutors).setMaximumPoolSize(anyInt()); verifyNoMoreInteractions(rollupReadExecutors); } |
MaxValue extends AbstractRollupStat { @Override void handleRollupMetric(IBaseRollup baseRollup) throws RuntimeException { AbstractRollupStat other = baseRollup.getMaxValue(); if (init) { if (other.isFloatingPoint()) { this.setDoubleValue(other.toDouble()); } else { this.setLongValue(other.toLong()); } this.init = false... | @Test public void rollupInitialFloatingPointSetsValue() { double value = 123.45d; IBaseRollup rollup = mock(IBaseRollup.class); MaxValue other = new MaxValue(value); doReturn(other).when(rollup).getMaxValue(); max.handleRollupMetric(rollup); assertTrue(max.isFloatingPoint()); assertEquals(value, max.toDouble(), 0.00001... |
RollupService implements Runnable, RollupServiceMBean { public synchronized int getQueuedRollupCount() { return rollupReadExecutors.getQueue().size(); } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
... | @Test public void getQueuedRollupCountReturnsQueueSize() { BlockingQueue<Runnable> queue = mock(BlockingQueue.class); int expected1 = 123; int expected2 = 45; when(queue.size()).thenReturn(expected1).thenReturn(expected2); when(rollupReadExecutors.getQueue()).thenReturn(queue); int count = service.getQueuedRollupCount(... |
MaxValue extends AbstractRollupStat { @Override public byte getStatType() { return Constants.MAX; } MaxValue(); @SuppressWarnings("unused") // used by Jackson MaxValue(long value); @SuppressWarnings("unused") // used by Jackson MaxValue(double value); @Override byte getStatType(); } | @Test public void returnsTheCorrectStatType() { assertEquals(Constants.MAX, max.getStatType()); } |
Token { public static List<Token> getTokens(Locator locator) { if (StringUtils.isEmpty(locator.getMetricName()) || StringUtils.isEmpty(locator.getTenantId())) return new ArrayList<>(); String[] tokens = locator.getMetricName().split(Locator.METRIC_TOKEN_SEPARATOR_REGEX); return IntStream.range(0, tokens.length) .mapToO... | @Test public void testGetTokensHappyCase() { String tenantID = "111111"; String metricName = "a.b.c.d"; Locator locator = Locator.createLocatorFromPathComponents(tenantID, metricName); String[] expectedTokens = new String[] {"a", "b", "c", "d"}; String[] expectedParents = new String[] { "", "a", "a.b", "a.b.c"}; String... |
RollupService implements Runnable, RollupServiceMBean { public synchronized int getInFlightRollupCount() { return rollupReadExecutors.getActiveCount(); } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
... | @Test public void testGetInFlightRollupCount() { int expected1 = 123; int expected2 = 45; when(rollupReadExecutors.getActiveCount()) .thenReturn(expected1) .thenReturn(expected2); int count = service.getInFlightRollupCount(); assertEquals(expected1, count); count = service.getInFlightRollupCount(); assertEquals(expecte... |
SlotKeySerDes { protected static int shardFromSlotKey(String s) { return Integer.parseInt(s.split(",", -1)[2]); } static SlotKey deserialize(String stateStr); String serialize(SlotKey slotKey); String serialize(Granularity gran, int slot, int shard); } | @Test public void testShardFromSlotKey() { int expectedShard = 1; int shard = SlotKeySerDes.shardFromSlotKey(SlotKey.of(Granularity.MIN_5, 10, expectedShard).toString()); Assert.assertEquals(expectedShard, shard); } |
SimpleNumber implements Rollup { public String toString() { switch (type) { case INTEGER: return String.format("%d (int)", value.intValue()); case LONG: return String.format("%d (long)", value.longValue()); case DOUBLE: return String.format("%s (double)", value.toString()); default: return super.toString(); } } SimpleN... | @Test public void toStringWithIntegerPrintsIntegerString() { SimpleNumber sn = new SimpleNumber(123); assertEquals("123 (int)", sn.toString()); }
@Test public void toStringWithLongPrintsLongString() { SimpleNumber sn = new SimpleNumber(123L); assertEquals("123 (long)", sn.toString()); }
@Test public void toStringWithDo... |
SimpleNumber implements Rollup { @Override public RollupType getRollupType() { return RollupType.NOT_A_ROLLUP; } SimpleNumber(Object value); @Override Boolean hasData(); Number getValue(); Type getDataType(); String toString(); @Override RollupType getRollupType(); @Override int hashCode(); @Override boolean equals(Obj... | @Test public void rollupTypeIsNotTypical() { SimpleNumber sn = new SimpleNumber(123.45d); assertEquals(RollupType.NOT_A_ROLLUP, sn.getRollupType()); } |
SimpleNumber implements Rollup { @Override public int hashCode() { return value.hashCode(); } SimpleNumber(Object value); @Override Boolean hasData(); Number getValue(); Type getDataType(); String toString(); @Override RollupType getRollupType(); @Override int hashCode(); @Override boolean equals(Object obj); } | @Test public void hashCodeIsValuesHashCode() { Double value = 123.45d; SimpleNumber sn = new SimpleNumber(value); assertEquals(value.hashCode(), sn.hashCode()); } |
SimpleNumber implements Rollup { @Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof SimpleNumber)) return false; SimpleNumber other = (SimpleNumber)obj; return other.value == this.value || other.value.equals(this.value); } SimpleNumber(Object value); @Override Boolean hasData(); Number ge... | @Test public void equalsWithNullReturnsFalse() { SimpleNumber sn = new SimpleNumber(123.45d); assertFalse(sn.equals(null)); }
@Test public void equalsWithOtherTypeReturnsFalse() { SimpleNumber sn = new SimpleNumber(123.45d); assertFalse(sn.equals(Double.valueOf(123.45d))); }
@Test public void equalsWithSimpleNumberOfOt... |
RollupService implements Runnable, RollupServiceMBean { public synchronized boolean getActive() { return active; } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
ThreadPoolExecutor ... | @Test public void getActiveGetsActiveFlag() { assertEquals(true, service.getActive()); } |
Variance extends AbstractRollupStat { @Override public double toDouble() { if (needsCompute) compute(); return super.toDouble(); } Variance(); @SuppressWarnings("unused") // used by Jackson Variance(double value); @Override boolean equals(Object otherObject); @Override boolean isFloatingPoint(); String toString(); @Ov... | @Test public void testRollupVariance() throws IOException { int size = TestData.DOUBLE_SRC.length; int GROUPS = 4; int windowSize = size/GROUPS; double[][] input = new double[GROUPS][windowSize]; int count = 0; int i = 0; int j = 0; for (double val : TestData.DOUBLE_SRC) { input[i][j] = val; j++; count++; if (count % w... |
BluefloodTimerRollup implements Rollup, IBaseRollup { public static double calculatePerSecond(long countA, double countPerSecA, long countB, double countPerSecB) { double totalCount = countA + countB; double totalTime = ((double)countA / countPerSecA) + ((double)countB / countPerSecB); return totalCount / totalTime; } ... | @Test public void testCountPerSecondCalculation() { Assert.assertEquals(7.5d, BluefloodTimerRollup.calculatePerSecond(150, 5d, 300, 10d)); } |
BluefloodTimerRollup implements Rollup, IBaseRollup { public BluefloodTimerRollup withSampleCount(int sampleCount) { this.sampleCount = sampleCount; return this; } BluefloodTimerRollup(); BluefloodTimerRollup withSum(double sum); BluefloodTimerRollup withCount(long count); BluefloodTimerRollup withCountPS(double count_... | @Test public void testNullVersusZero() throws IOException { final BluefloodTimerRollup timerWithData = new BluefloodTimerRollup() .withSampleCount(1); final BluefloodTimerRollup timerWithoutData = new BluefloodTimerRollup() .withSampleCount(0); Assert.assertNotSame(timerWithData, timerWithoutData); } |
BluefloodTimerRollup implements Rollup, IBaseRollup { public static Number sum(Collection<Number> numbers) { long longSum = 0; double doubleSum = 0d; boolean useDouble = false; for (Number number : numbers) { if (useDouble || number instanceof Double || number instanceof Float) { if (!useDouble) { useDouble = true; dou... | @Test public void testSum() { Assert.assertEquals(6L, BluefloodTimerRollup.sum(longs)); Assert.assertEquals(6.0d, BluefloodTimerRollup.sum(doubles)); Assert.assertEquals(6.0d, BluefloodTimerRollup.sum(mixed)); Assert.assertEquals(6.0d, BluefloodTimerRollup.sum(alsoMixed)); } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.