| 1 |
/* |
| 2 |
* Copyright (c) 2021 Goldman Sachs. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* and Eclipse Distribution License v. 1.0 which accompany this distribution. |
| 6 |
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* and the Eclipse Distribution License is available at |
| 8 |
* http://www.eclipse.org/org/documents/edl-v10.php. |
| 9 |
*/ |
| 10 |
|
| 11 |
package org.eclipse.collections.impl.bag.mutable |
| 12 |
|
| 13 |
import org.eclipse.collections.api.bag.MutableBag |
| 14 |
import org.eclipse.collections.impl.Prelude._ |
| 15 |
import org.eclipse.collections.impl.block.factory.primitive.IntPredicates |
| 16 |
import org.eclipse.collections.impl.list.mutable.FastList |
| 17 |
import org.junit.Test |
| 18 |
|
| 19 |
class MultiReaderHashBagScalaTest extends MultiReaderHashBagTestTrait |
| 20 |
{ |
| 21 |
val classUnderTest = MultiReaderHashBag.newBagWith(1, 1, 2) |
| 22 |
|
| 23 |
@Test |
| 24 |
def newBag_safe(): Unit = |
| 25 |
this.assert(readersBlocked = false, writersBlocked = false) |
| 26 |
{ |
| 27 |
MultiReaderHashBag.newBag |
| 28 |
} |
| 29 |
|
| 30 |
@Test |
| 31 |
def newBagCapacity_safe(): Unit = |
| 32 |
this.assert(readersBlocked = false, writersBlocked = false) |
| 33 |
{ |
| 34 |
MultiReaderHashBag.newBag(5) |
| 35 |
} |
| 36 |
|
| 37 |
@Test |
| 38 |
def newBagIterable_safe(): Unit = |
| 39 |
this.assert(readersBlocked = false, writersBlocked = false) |
| 40 |
{ |
| 41 |
MultiReaderHashBag.newBag(FastList.newListWith(1, 2)) |
| 42 |
} |
| 43 |
|
| 44 |
@Test |
| 45 |
def newBagWith_safe(): Unit = |
| 46 |
this.assert(readersBlocked = false, writersBlocked = false) |
| 47 |
{ |
| 48 |
MultiReaderHashBag.newBagWith(1, 2) |
| 49 |
} |
| 50 |
|
| 51 |
@Test |
| 52 |
def addOccurrences_safe(): Unit = |
| 53 |
this.assert(readersBlocked = true, writersBlocked = true) |
| 54 |
{ |
| 55 |
this.classUnderTest.addOccurrences(1, 2) |
| 56 |
} |
| 57 |
|
| 58 |
@Test |
| 59 |
def removeOccurrences_safe(): Unit = |
| 60 |
this.assert(readersBlocked = true, writersBlocked = true) |
| 61 |
{ |
| 62 |
this.classUnderTest.removeOccurrences(1, 1) |
| 63 |
} |
| 64 |
|
| 65 |
@Test |
| 66 |
def occurrencesOf_safe(): Unit = |
| 67 |
this.assert(readersBlocked = false, writersBlocked = true) |
| 68 |
{ |
| 69 |
this.classUnderTest.occurrencesOf(1) |
| 70 |
} |
| 71 |
|
| 72 |
@Test |
| 73 |
def sizeDistinct_safe(): Unit = |
| 74 |
this.assert(readersBlocked = false, writersBlocked = true) |
| 75 |
{ |
| 76 |
this.classUnderTest.sizeDistinct |
| 77 |
} |
| 78 |
|
| 79 |
@Test |
| 80 |
def toMapOfItemToCount_safe(): Unit = |
| 81 |
this.assert(readersBlocked = false, writersBlocked = true) |
| 82 |
{ |
| 83 |
this.classUnderTest.toMapOfItemToCount |
| 84 |
} |
| 85 |
|
| 86 |
@Test |
| 87 |
def toStringOfItemToCount_safe(): Unit = |
| 88 |
this.assert(readersBlocked = false, writersBlocked = true) |
| 89 |
{ |
| 90 |
this.classUnderTest.toStringOfItemToCount |
| 91 |
} |
| 92 |
|
| 93 |
@Test |
| 94 |
def iteratorWithReadLock_safe(): Unit = |
| 95 |
this.assert(readersBlocked = false, writersBlocked = true) |
| 96 |
{ |
| 97 |
this.classUnderTest.withReadLockAndDelegate((each: MutableBag[Int]) => |
| 98 |
{ |
| 99 |
each.iterator |
| 100 |
() |
| 101 |
}) |
| 102 |
} |
| 103 |
|
| 104 |
@Test |
| 105 |
def iteratorWithWriteLock_safe(): Unit = |
| 106 |
this.assert(readersBlocked = true, writersBlocked = true) |
| 107 |
{ |
| 108 |
this.classUnderTest.withWriteLockAndDelegate((each: MutableBag[Int]) => |
| 109 |
{ |
| 110 |
each.iterator |
| 111 |
() |
| 112 |
}) |
| 113 |
} |
| 114 |
|
| 115 |
@Test |
| 116 |
def forEachWithOccurrences_safe(): Unit = |
| 117 |
this.assert(readersBlocked = false, writersBlocked = true) |
| 118 |
{ |
| 119 |
this.classUnderTest.forEachWithOccurrences((_: Int, _: Int) => ()) |
| 120 |
} |
| 121 |
|
| 122 |
@Test |
| 123 |
def selectByOccurrences_safe(): Unit = |
| 124 |
this.assert(readersBlocked = false, writersBlocked = true) |
| 125 |
{ |
| 126 |
this.classUnderTest.selectByOccurrences(IntPredicates.isOdd) |
| 127 |
} |
| 128 |
} |