use of java.util.concurrent.ThreadLocalRandom in project Glowstone by GlowstoneMC.
the class GlowEvoker method castSpell.
public void castSpell(Spell spell) {
setCurrentSpell(spell);
ThreadLocalRandom random = ThreadLocalRandom.current();
switch(spell) {
case FANGS:
{
// todo
break;
}
case SUMMON:
{
world.playSound(location, Sound.ENTITY_EVOCATION_ILLAGER_PREPARE_SUMMON, 1.0f, 1.0f);
int count = 3;
for (int i = 0; i < count; i++) {
double y = random.nextDouble() + 0.5 + location.getY();
double radius = 0.5 + random.nextDouble();
double angle = random.nextDouble() * 2 * Math.PI;
double x = radius * Math.sin(angle) + location.getX();
double z = radius * Math.cos(angle) + location.getZ();
Location location = new Location(world, x, y, z);
world.spawnEntity(location, EntityType.VEX);
}
break;
}
case WOLOLO:
{
// todo
break;
}
}
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class TrackingPageIOTest method checkFindingRandomly.
/**
* @param buf Buffer.
* @param backupId Backup id.
*/
private void checkFindingRandomly(ByteBuffer buf, int backupId) {
ThreadLocalRandom rand = ThreadLocalRandom.current();
int track = io.countOfPageToTrack(PAGE_SIZE);
long basePageId = io.trackingPageFor(Math.max(rand.nextLong(Integer.MAX_VALUE - track), 0), PAGE_SIZE);
long maxId = basePageId + rand.nextInt(1, track);
assert basePageId >= 0;
PageIO.setPageId(GridUnsafe.bufferAddress(buf), basePageId);
try {
TreeSet<Long> setIdx = new TreeSet<>();
generateMarking(buf, track, basePageId, maxId, setIdx, backupId, backupId - 1);
for (long pageId = basePageId; pageId < basePageId + track; pageId++) {
Long foundNextChangedPage = io.findNextChangedPage(buf, pageId, backupId, backupId - 1, PAGE_SIZE);
if (io.trackingPageFor(pageId, PAGE_SIZE) == pageId)
assertEquals((Long) pageId, foundNextChangedPage);
else if (setIdx.contains(pageId))
assertEquals((Long) pageId, foundNextChangedPage);
else {
NavigableSet<Long> tailSet = setIdx.tailSet(pageId, false);
Long next = tailSet.isEmpty() ? null : tailSet.first();
assertEquals(next, foundNextChangedPage);
}
}
} catch (Throwable e) {
System.out.println("snapshotId = " + backupId + ", basePageId = " + basePageId);
throw e;
}
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class TrackingPageIOTest method generateMarking.
private void generateMarking(ByteBuffer buf, int track, long basePageId, long maxPageId, Set<Long> setIdx, int backupId, int successfulBackupId) {
ThreadLocalRandom rand = ThreadLocalRandom.current();
for (long i = basePageId; i < basePageId + track; i++) {
boolean changed = (i == basePageId || rand.nextDouble() < 0.1) && i < maxPageId;
if (changed) {
io.markChanged(buf, i, backupId, successfulBackupId, PAGE_SIZE);
setIdx.add(i);
}
}
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class TrackingPageIOTest method testMerging_MarksShouldBeDropForSuccessfulBackup.
/**
*
*/
public void testMerging_MarksShouldBeDropForSuccessfulBackup() {
ByteBuffer buf = ByteBuffer.allocateDirect(PAGE_SIZE);
buf.order(ByteOrder.nativeOrder());
ThreadLocalRandom rand = ThreadLocalRandom.current();
int track = io.countOfPageToTrack(PAGE_SIZE);
long basePageId = io.trackingPageFor(Math.max(rand.nextLong(Integer.MAX_VALUE - track), 0), PAGE_SIZE);
assert basePageId >= 0;
PageIO.setPageId(GridUnsafe.bufferAddress(buf), basePageId);
TreeSet<Long> setIdx = new TreeSet<>();
for (int i = 0; i < 4; i++) generateMarking(buf, track, basePageId, basePageId + rand.nextInt(1, track), setIdx, i, -1);
setIdx.clear();
generateMarking(buf, track, basePageId, basePageId + rand.nextInt(1, track), setIdx, 4, -1);
TreeSet<Long> setIdx2 = new TreeSet<>();
generateMarking(buf, track, basePageId, basePageId + rand.nextInt(1, track), setIdx2, 5, 3);
assertEquals(setIdx.size(), io.countOfChangedPage(buf, 4, PAGE_SIZE));
assertEquals(setIdx2.size(), io.countOfChangedPage(buf, 5, PAGE_SIZE));
for (long i = basePageId; i < basePageId + track; i++) assertEquals("pageId = " + i, setIdx2.contains(i), io.wasChanged(buf, i, 5, 4, PAGE_SIZE));
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class TrackingPageIOTest method checkMarkingRandomly.
/**
* @param buf Buffer.
* @param backupId Backup id.
*/
private void checkMarkingRandomly(ByteBuffer buf, int backupId, boolean testZeroing) {
ThreadLocalRandom rand = ThreadLocalRandom.current();
int track = io.countOfPageToTrack(PAGE_SIZE);
long basePageId = io.trackingPageFor(Math.max(rand.nextLong(Integer.MAX_VALUE - track), 0), PAGE_SIZE);
long maxId = testZeroing ? basePageId + rand.nextInt(1, track) : basePageId + track;
assert basePageId >= 0;
PageIO.setPageId(GridUnsafe.bufferAddress(buf), basePageId);
Map<Long, Boolean> map = new HashMap<>();
int cntOfChanged = 0;
try {
for (long i = basePageId; i < basePageId + track; i++) {
boolean changed = (i == basePageId || rand.nextDouble() < 0.5) && i < maxId;
map.put(i, changed);
if (changed) {
io.markChanged(buf, i, backupId, backupId - 1, PAGE_SIZE);
cntOfChanged++;
}
assertEquals(basePageId, PageIO.getPageId(buf));
assertEquals(cntOfChanged, io.countOfChangedPage(buf, backupId, PAGE_SIZE));
}
assertEquals(cntOfChanged, io.countOfChangedPage(buf, backupId, PAGE_SIZE));
for (Map.Entry<Long, Boolean> e : map.entrySet()) assertEquals(e.getValue().booleanValue(), io.wasChanged(buf, e.getKey(), backupId, backupId - 1, PAGE_SIZE));
} catch (Throwable e) {
System.out.println("snapshotId = " + backupId + ", basePageId = " + basePageId);
throw e;
}
}
Aggregations