@Test public void json() throws Exception { WorkerInfo workerInfo = createRandom(); ObjectMapper mapper = new ObjectMapper(); WorkerInfo other = mapper.readValue(mapper.writeValueAsBytes(workerInfo), WorkerInfo.class); checkEquality(workerInfo, other); }
@Test public void lastContactSecComparator() { Assert.assertTrue(compareLostWorkersWithTimes(0, 1) < 0); Assert.assertTrue(compareLostWorkersWithTimes(1, 0) > 0); Assert.assertTrue(compareLostWorkersWithTimes(1, 1) == 0); Assert.assertTrue(compareLostWorkersWithTimes(-1, 1) < 0); Assert.assertTrue(compareLostWorkersWithTimes(1, -1) > 0); }
private static int compareLostWorkersWithTimes(int time1, int time2) { WorkerInfo.LastContactSecComparator comparator = new WorkerInfo.LastContactSecComparator(); WorkerInfo worker1 = createRandom(); WorkerInfo worker2 = createRandom(); worker1.setLastContactSec(time1); worker2.setLastContactSec(time2); return comparator.compare(worker1, worker2); }
long numLostWorkers = random.nextInt(10); for (int i = 0; i < numLostWorkers; i++) { lostWorkers.add(WorkerInfoTest.createRandom()); long numWorkers = random.nextInt(10); for (int i = 0; i < numWorkers; i++) { workers.add(WorkerInfoTest.createRandom());
@Test public void proto() { WorkerInfo workerInfo = createRandom(); WorkerInfo other = GrpcUtils.fromProto(GrpcUtils.toProto(workerInfo)); checkEquality(workerInfo, other); }