-
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Allow MaxBreadcrumb 0 / Expose MaxBreadcrumb metadata. (#3836)
* expose max-breadcrumbs on meta data and implement disabled queue when maxbreadcrumbs sets to 0 * missing queue class and test * update changelog --------- Co-authored-by: Lucas <luca-zimerman1@hotmail.com> Co-authored-by: Stefano <stefano.siano91@gmail.com>
- Loading branch information
1 parent
28a11a7
commit 2af8d1a
Showing
8 changed files
with
257 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package io.sentry; | ||
|
||
import java.io.Serializable; | ||
import java.util.AbstractCollection; | ||
import java.util.Iterator; | ||
import java.util.NoSuchElementException; | ||
import java.util.Queue; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
final class DisabledQueue<E> extends AbstractCollection<E> implements Queue<E>, Serializable { | ||
|
||
/** Serialization version. */ | ||
private static final long serialVersionUID = -8423413834657610417L; | ||
|
||
/** Constructor that creates a queue that does not accept any element. */ | ||
public DisabledQueue() {} | ||
|
||
// ----------------------------------------------------------------------- | ||
/** | ||
* Returns the number of elements stored in the queue. | ||
* | ||
* @return this queue's size | ||
*/ | ||
@Override | ||
public int size() { | ||
return 0; | ||
} | ||
|
||
/** | ||
* Returns true if this queue is empty; false otherwise. | ||
* | ||
* @return false | ||
*/ | ||
@Override | ||
public boolean isEmpty() { | ||
return false; | ||
} | ||
|
||
/** Does nothing. */ | ||
@Override | ||
public void clear() {} | ||
|
||
/** | ||
* Since the queue is disabled, the element will not be added. | ||
* | ||
* @param element the element to add | ||
* @return false, always | ||
*/ | ||
@Override | ||
public boolean add(final @NotNull E element) { | ||
return false; | ||
} | ||
|
||
// ----------------------------------------------------------------------- | ||
|
||
/** | ||
* Receives an element but do nothing with it. | ||
* | ||
* @param element the element to add | ||
* @return false, always | ||
*/ | ||
@Override | ||
public boolean offer(@NotNull E element) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public @Nullable E poll() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public @Nullable E element() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public @Nullable E peek() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public @NotNull E remove() { | ||
throw new NoSuchElementException("queue is disabled"); | ||
} | ||
|
||
// ----------------------------------------------------------------------- | ||
|
||
/** | ||
* Returns an iterator over this queue's elements. | ||
* | ||
* @return an iterator over this queue's elements | ||
*/ | ||
@Override | ||
public @NotNull Iterator<E> iterator() { | ||
return new Iterator<E>() { | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public E next() { | ||
throw new NoSuchElementException(); | ||
} | ||
|
||
@Override | ||
public void remove() { | ||
throw new IllegalStateException(); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package io.sentry | ||
import org.junit.Assert.assertThrows | ||
import java.util.NoSuchElementException | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFalse | ||
import kotlin.test.assertNull | ||
|
||
class DisabledQueueTest { | ||
|
||
@Test | ||
fun `size starts empty`() { | ||
val queue = DisabledQueue<Int>() | ||
assertEquals(0, queue.size, "Size should always be zero.") | ||
} | ||
|
||
@Test | ||
fun `add does not add elements`() { | ||
val queue = DisabledQueue<Int>() | ||
assertFalse(queue.add(1), "add should always return false.") | ||
assertEquals(0, queue.size, "Size should still be zero after attempting to add an element.") | ||
} | ||
|
||
@Test | ||
fun `isEmpty returns false when created`() { | ||
val queue = DisabledQueue<Int>() | ||
assertFalse(queue.isEmpty(), "isEmpty should always return false.") | ||
} | ||
|
||
@Test | ||
fun `isEmpty always returns false if add function was called`() { | ||
val queue = DisabledQueue<Int>() | ||
queue.add(1) | ||
|
||
assertFalse(queue.isEmpty(), "isEmpty should always return false.") | ||
} | ||
|
||
@Test | ||
fun `offer does not add elements`() { | ||
val queue = DisabledQueue<Int>() | ||
assertFalse(queue.offer(1), "offer should always return false.") | ||
assertEquals(0, queue.size, "Size should still be zero after attempting to offer an element.") | ||
} | ||
|
||
@Test | ||
fun `poll returns null`() { | ||
val queue = DisabledQueue<Int>() | ||
queue.add(1) | ||
assertNull(queue.poll(), "poll should always return null.") | ||
} | ||
|
||
@Test | ||
fun `peek returns null`() { | ||
val queue = DisabledQueue<Int>() | ||
queue.add(1) | ||
|
||
assertNull(queue.peek(), "peek should always return null.") | ||
} | ||
|
||
@Test | ||
fun `element returns null`() { | ||
val queue = DisabledQueue<Int>() | ||
assertNull(queue.element(), "element should always return null.") | ||
} | ||
|
||
@Test | ||
fun `remove throws NoSuchElementException`() { | ||
val queue = DisabledQueue<Int>() | ||
assertThrows(NoSuchElementException::class.java) { queue.remove() } | ||
} | ||
|
||
@Test | ||
fun `clear does nothing`() { | ||
val queue = DisabledQueue<Int>() | ||
queue.clear() // Should not throw an exception | ||
assertEquals(0, queue.size, "Size should remain zero after clear.") | ||
} | ||
|
||
@Test | ||
fun `iterator has no elements`() { | ||
val queue = DisabledQueue<Int>() | ||
val iterator = queue.iterator() | ||
assertFalse(iterator.hasNext(), "Iterator should have no elements.") | ||
assertThrows(NoSuchElementException::class.java) { iterator.next() } | ||
} | ||
|
||
@Test | ||
fun `iterator remove throws IllegalStateException`() { | ||
val queue = DisabledQueue<Int>() | ||
val iterator = queue.iterator() | ||
assertThrows(IllegalStateException::class.java) { iterator.remove() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters