use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidEntityRepositoryTest method createAndGet.
@Test
public void createAndGet() throws Exception {
final String id = "id1";
final RaidEntity raidEntity = entityRepository.save(new RaidEntity(id, "Mupp", LocalDateTime.now().plusMinutes(20), "Thegym", "Theuser", "Theregion"));
assertNotNull(raidEntity);
assertThat(entityRepository.findOne(id), is(raidEntity));
}
use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidEntityRepositoryTest method createSignUp.
@Transactional(propagation = Propagation.REQUIRES_NEW)
public RaidEntitySignUp createSignUp(String id, Integer thread, LocalTime now, Random random, int i) {
RaidEntitySignUp signUp = new RaidEntitySignUp("Mupp" + thread + "_" + i, random.nextInt(4) + 1, printTime(now));
RaidEntity entity = entityRepository.findOne(id);
entity.addSignUp(signUp);
entityRepository.save(entity);
LOGGER.warn("Created: " + signUp);
return signUp;
}
use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidEntityRepositoryTest method deleteSomeSignUps.
@Transactional(propagation = Propagation.REQUIRES_NEW)
public int deleteSomeSignUps(String id) {
int numberDeleted = 0;
final RaidEntity theEntity = entityRepository.findOne(id);
for (RaidEntitySignUp signUp : theEntity.getSignUpsAsSet()) {
if (signUp.getNumberOfPeople().equals(3)) {
theEntity.removeSignUp(signUp);
LOGGER.warn("Removed: " + signUp);
numberDeleted++;
}
}
entityRepository.save(theEntity);
return numberDeleted;
}
use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidEntityRepositoryTest method createWithGroup.
@Test
public void createWithGroup() throws Exception {
final String id = "id1";
RaidEntity raidEntity = new RaidEntity(id, "Mupp", LocalDateTime.now().plusMinutes(20), "Thegym", "Theuser", "Theregion");
final RaidGroup group = new RaidGroup("testserver", "channel", "abc1", "abc2", "testId", LocalDateTime.now().plusMinutes(10));
assertThat(raidEntity.addGroup(group), is(true));
raidEntity = entityRepository.save(raidEntity);
final RaidEntity loaded = entityRepository.findOne(id);
assertThat(loaded, is(raidEntity));
final Set<RaidGroup> groups = loaded.getGroupsAsSet();
assertThat(groups.size(), is(1));
assertThat(groups.iterator().next(), is(group));
final List<RaidGroup> groupsForServer = entityRepository.findGroupsForServer("testserver");
assertThat(groupsForServer.size(), is(1));
assertThat(groupsForServer.iterator().next(), is(group));
}
use of pokeraidbot.infrastructure.jpa.raid.RaidEntity in project pokeraidbot by magnusmickelsson.
the class RaidEntityRepositoryTest method createWithSignupsTryToCleanUpWithoutConcurrentModificationException.
@Test
public void createWithSignupsTryToCleanUpWithoutConcurrentModificationException() throws Exception {
final String id = "id1";
final RaidEntity raidEntity = entityRepository.save(new RaidEntity(id, "Mupp", LocalDateTime.now().plusMinutes(20), "Thegym", "Theuser", "Theregion"));
final LocalTime now = LocalTime.now();
// Create signups with 100 ms interval, during ~3 seconds
Callable<Integer> creatingSignUpsTask = () -> {
int numberOfSignUpsCreated = 0;
final Random random = new Random();
for (int i = 0; i < 30; i++) {
Thread.sleep(100);
createSignUp(id, 1, now, random, i);
numberOfSignUpsCreated++;
}
return numberOfSignUpsCreated;
};
Callable<Integer> creatingSignUpsTask2 = () -> {
int numberOfSignUpsCreated = 0;
final Random random = new Random();
for (int i = 0; i < 30; i++) {
Thread.sleep(100);
createSignUp(id, 2, now, random, i);
numberOfSignUpsCreated++;
}
return numberOfSignUpsCreated;
};
// After 2 seconds, try and remove all signups for a certain time
Callable<Integer> cleanUpSignUpsTask = () -> {
Thread.sleep(2000);
int numberDeleted = deleteSomeSignUps(id);
return numberDeleted;
};
final List<Future<Integer>> futures = executorService.invokeAll(Arrays.asList(cleanUpSignUpsTask, creatingSignUpsTask, creatingSignUpsTask2));
final RaidEntity theEntity = entityRepository.findOne(id);
assertThat(theEntity == null, is(false));
final Iterator<Future<Integer>> futureIterator = futures.iterator();
final Future<Integer> cleanedUpFuture = futureIterator.next();
final Future<Integer> signupFuture1 = futureIterator.next();
final Future<Integer> signupFuture2 = futureIterator.next();
final Integer signedUpInThread1 = signupFuture1.get();
final Integer signedUpInThread2 = signupFuture2.get();
final Integer cleanedUp = cleanedUpFuture.get();
int signups = signedUpInThread1 + signedUpInThread2 - cleanedUp;
assertThat(signedUpInThread1, is(30));
assertThat(signedUpInThread2, is(30));
assertThat(cleanedUp > 0, is(true));
assertThat(theEntity.getSignUpsAsSet().size(), is(signups));
}
Aggregations