/** * {@inheritDoc} */ @Override public SELF containsExactlyElementsOf(Iterable<? extends ELEMENT> iterable) { return containsExactly(toArray(iterable)); }
/** * {@inheritDoc} */ @Override public SELF containsExactlyElementsOf(Iterable<? extends ELEMENT> iterable) { return containsExactly(toArray(iterable)); }
@Test public void sortAndSearch() { List<String> list = ListUtil.newArrayList("d", "a", "c", "b", "e", "i", "g"); ListUtil.sort(list); assertThat(list).hasSize(7).containsExactly("a", "b", "c", "d", "e", "g", "i"); ListUtil.shuffle(list); ListUtil.shuffle(list, new Random()); System.out.println("shuffle list:" + list); ListUtil.sort(list, Ordering.natural()); assertThat(list).hasSize(7).containsExactly("a", "b", "c", "d", "e", "g", "i"); assertThat(ListUtil.binarySearch(list, "b")).isEqualTo(1); assertThat(ListUtil.binarySearch(list, "b", Ordering.natural())).isEqualTo(1); assertThat(ListUtil.binarySearch(list, "x")).isEqualTo(-8); // reverse List list8 = ListUtil.reverse(list); assertThat(list8).hasSize(7).containsExactly("i", "g", "e", "d", "c", "b", "a"); // sortReverse ListUtil.shuffle(list8); ListUtil.sortReverse(list8); assertThat(list8).hasSize(7).containsExactly("i", "g", "e", "d", "c", "b", "a"); ListUtil.shuffle(list8); ListUtil.sortReverse(list8, Ordering.natural()); assertThat(list8).hasSize(7).containsExactly("i", "g", "e", "d", "c", "b", "a"); }
@Test public void handleMessage_syncId() throws IOException { final Message message = new Message(); message.what = 1; executor.handleMessage(message); verify(agent).syncCacheToDB(eq(1)); assertThat(freeToDBIdList).containsExactly(1); } }
@Test public void handleMessage_syncBunchId() throws IOException { final Message message = new Message(); message.what = WHAT_SYNC_BUNCH_ID; message.obj = idList; executor.handleMessage(message); verify(agent).syncCacheToDB(eq(idList)); assertThat(freeToDBIdList).containsExactly(1, 2, 3); }
@Test public void inspectForConflict_sameTask() throws IOException { mockOkDownload(); final CallbackDispatcher callbackDispatcher = OkDownload.with().callbackDispatcher(); final DownloadListener listener = callbackDispatcher.dispatch(); DownloadTask task = mock(DownloadTask.class); final Collection<DownloadCall> calls = new ArrayList<>(); final Collection<DownloadTask> sameTaskList = new ArrayList<>(); final Collection<DownloadTask> fileBusyList = new ArrayList<>(); final DownloadCall call = mock(DownloadCall.class); when(call.equalsTask(task)).thenReturn(true); calls.add(call); assertThat(dispatcher.inspectForConflict(task, calls, sameTaskList, fileBusyList)).isTrue(); assertThat(sameTaskList).containsExactly(task); assertThat(fileBusyList).isEmpty(); verify(listener, never()).taskEnd(eq(task), any(EndCause.class), nullable(Exception.class)); }
@Test public void inspectForConflict_fileBusy() throws IOException { mockOkDownload(); final CallbackDispatcher callbackDispatcher = OkDownload.with().callbackDispatcher(); final DownloadListener listener = callbackDispatcher.dispatch(); DownloadTask task = mock(DownloadTask.class); final Collection<DownloadCall> calls = new ArrayList<>(); final Collection<DownloadTask> sameTaskList = new ArrayList<>(); final Collection<DownloadTask> fileBusyList = new ArrayList<>(); final DownloadCall call = mock(DownloadCall.class); final File file = mock(File.class); when(task.getFile()).thenReturn(file); when(call.getFile()).thenReturn(file); calls.add(call); assertThat(dispatcher.inspectForConflict(task, calls, sameTaskList, fileBusyList)).isTrue(); assertThat(sameTaskList).isEmpty(); assertThat(fileBusyList).containsExactly(task); verify(listener, never()).taskEnd(eq(task), any(EndCause.class), nullable(Exception.class)); }
@Test public void inspectCompleted_collection() throws IOException { mockOkDownload(); final DownloadStrategy downloadStrategy = OkDownload.with().downloadStrategy(); final CallbackDispatcher callbackDispatcher = OkDownload.with().callbackDispatcher(); final DownloadListener listener = callbackDispatcher.dispatch(); final DownloadTask task = mock(DownloadTask.class); when(task.isPassIfAlreadyCompleted()).thenReturn(true); when(task.getId()).thenReturn(0); when(task.getUrl()).thenReturn("url"); when(task.getParentFile()).thenReturn(existFile.getParentFile()); final BreakpointStore store = OkDownload.with().breakpointStore(); doReturn(existFile.getName()).when(store).getResponseFilename("url"); doReturn(true).when(downloadStrategy).validFilenameFromStore(task); final Collection<DownloadTask> completedCollection = new ArrayList<>(); assertThat(dispatcher.inspectCompleted(task, completedCollection)).isTrue(); verify(listener, never()).taskEnd(eq(task), any(EndCause.class), nullable(Exception.class)); assertThat(completedCollection).containsExactly(task); }
@Test public void enqueue_tasksWithNetworkNotAvailable() throws IOException { mockOkDownload(); final CallbackDispatcher callbackDispatcher = OkDownload.with().callbackDispatcher(); final DownloadStrategy downloadStrategy = OkDownload.with().downloadStrategy(); DownloadTask[] tasks = new DownloadTask[]{mock(DownloadTask.class), mock( DownloadTask.class), mock(DownloadTask.class)}; doThrow(UnknownHostException.class).when(downloadStrategy).inspectNetworkAvailable(); dispatcher.enqueue(tasks); final ArgumentCaptor<Collection<DownloadTask>> listCaptor = ArgumentCaptor .forClass(Collection.class); verify(callbackDispatcher, never()) .endTasks(any(Collection.class), any(Collection.class), any(Collection.class)); assertThat(readyAsyncCalls).isEmpty(); verify(dispatcher, never()).getExecutorService(); final ArgumentCaptor<Exception> causeCaptor = ArgumentCaptor.forClass(Exception.class); verify(callbackDispatcher).endTasksWithError(listCaptor.capture(), causeCaptor.capture()); assertThat(listCaptor.getValue()).containsExactly(tasks); assertThat(causeCaptor.getValue()).isExactlyInstanceOf(UnknownHostException.class); }
verify(callbackDispatcher).endTasksWithCanceled(callbackCanceledList.capture()); assertThat(callbackCanceledList.getValue()) .containsExactly(readyASyncCallTask, runningAsyncCallTask, runningSyncCallTask);
assertThat(command.states).hasSize(3).containsExactly(Thread.State.NEW, Thread.State.BLOCKED, Thread.State.RUNNABLE); assertThat(command.ints).hasSize(3).containsExactly(1, 2, 3); assertThat(command.strings).hasSize(1).containsExactly("a");
@Test(groups = "unit") public void should_return_query_plan_of_wrapped_policy() { when(wrappedPolicy.newQueryPlan(any(String.class), any(Statement.class))) .thenReturn(Iterators.forArray(host1, host2, host3)); HostFilterPolicy policy = new HostFilterPolicy(wrappedPolicy, null); assertThat(policy.newQueryPlan("keyspace", mock(Statement.class))) .containsExactly(host1, host2, host3); }
@Test(groups = "unit") public void should_respect_topological_order() { // given TokenAwarePolicy policy = new TokenAwarePolicy(childPolicy, TOPOLOGICAL); policy.init(cluster, null); // when Iterator<Host> queryPlan = policy.newQueryPlan("keyspace", statement); // then assertThat(queryPlan).containsExactly(host1, host2, host4, host3); }
@Test(groups = "unit") public void should_respect_child_policy_order() { // given TokenAwarePolicy policy = new TokenAwarePolicy(childPolicy, NEUTRAL); policy.init(cluster, null); // when Iterator<Host> queryPlan = policy.newQueryPlan("keyspace", statement); // then assertThat(queryPlan).containsExactly(host2, host1, host4, host3); }
assertThat(pool.trash).containsExactly(connection1); assertThat(pool.trash).containsExactly(connection1); assertThat(connection1.inFlight.get()).isEqualTo(50); assertThat(connection2.inFlight.get()).isEqualTo(50);
assertThat(pool.trash).containsExactly(connection1);
assertThat(pool.trash).containsExactly(connection1); assertThat(connection1.inFlight.get()).isEqualTo(51); assertThat(connection1.isClosed()).isFalse();
assertThat(command.states).hasSize(3).containsExactly(Thread.State.NEW, Thread.State.BLOCKED, Thread.State.RUNNABLE); assertThat(command.ints).hasSize(3).containsExactly(1, 2, 3); assertThat(command.strings).hasSize(1).containsExactly("a");
assertThat(initHostsCaptor.getValue()).containsExactly(host1);
UserType fooType = cluster2.getMetadata().getKeyspace("ks").getUserType("foo"); assertThat(fooType.getFieldNames()).containsExactly("i");