<commit_before>/*
 * Copyright (c) 2011-2016 Pivotal Software Inc, All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package reactor.core.publisher;

import java.time.Duration;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import reactor.core.Exceptions;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

public class BlockingTests {

	static Scheduler scheduler;

	@BeforeClass
	public static void before() {
		scheduler = Schedulers.fromExecutorService(Executors.newSingleThreadExecutor());
	}

	@AfterClass
	public static void after() {
		scheduler.dispose();
	}

	@Test
	public void blockingFirst() {
		Assert.assertEquals((Integer) 1,
				Flux.range(1, 10)
				    .publishOn(scheduler)
				    .blockFirst());
	}

	@Test
	public void blockingFirst2() {
		Assert.assertEquals((Integer) 1,
				Flux.range(1, 10)
				    .publishOn(scheduler)
				    .blockFirst(Duration.ofSeconds(10)));
	}

	@Test
	public void blockingFirstTimeout() {
		assertThat(Flux.empty()
		               .blockFirst(Duration.ofMillis(1))).isNull();
	}

	@Test
	public void blockingLast() {
		Assert.assertEquals((Integer) 10,
				Flux.range(1, 10)
				    .publishOn(scheduler)
				    .blockLast());
	}

	@Test
	public void blockingLast2() {
		Assert.assertEquals((Integer) 1,
				Flux.range(1, 10)
				    .publishOn(scheduler)
				    .blockLast(Duration.ofSeconds(10)));
	}

	@Test
	public void blockingLastTimeout() {
		assertThat(Flux.empty()
		               .blockLast(Duration.ofMillis(1))).isNull();
	}

	@Test(expected = RuntimeException.class)
	public void blockingFirstError() {
		Flux.error(new RuntimeException("test"))
		    .publishOn(scheduler)
		    .blockFirst();
	}

	@Test(expected = RuntimeException.class)
	public void blockingLastError() {
		Flux.error(new RuntimeException("test"))
		    .publishOn(scheduler)
		    .blockLast();
	}
<commit_msg>fix blocking test<commit_after>/*
 * Copyright (c) 2011-2016 Pivotal Software Inc, All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package reactor.core.publisher;

import java.time.Duration;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import reactor.core.Exceptions;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

public class BlockingTests {

	static Scheduler scheduler;

	@BeforeClass
	public static void before() {
		scheduler = Schedulers.fromExecutorService(Executors.newSingleThreadExecutor());
	}

	@AfterClass
	public static void after() {
		scheduler.dispose();
	}

	@Test
	public void blockingFirst() {
		Assert.assertEquals((Integer) 1,
				Flux.range(1, 10)
				    .publishOn(scheduler)
				    .blockFirst());
	}

	@Test
	public void blockingFirst2() {
		Assert.assertEquals((Integer) 1,
				Flux.range(1, 10)
				    .publishOn(scheduler)
				    .blockFirst(Duration.ofSeconds(10)));
	}

	@Test
	public void blockingFirstTimeout() {
		assertThat(Flux.empty()
		               .blockFirst(Duration.ofMillis(1))).isNull();
	}

	@Test
	public void blockingLast() {
		Assert.assertEquals((Integer) 10,
				Flux.range(1, 10)
				    .publishOn(scheduler)
				    .blockLast());
	}

	@Test
	public void blockingLast2() {
		Assert.assertEquals((Integer) 10,
				Flux.range(1, 10)
				    .publishOn(scheduler)
				    .blockLast(Duration.ofSeconds(10)));
	}

	@Test
	public void blockingLastTimeout() {
		assertThat(Flux.empty()
		               .blockLast(Duration.ofMillis(1))).isNull();
	}

	@Test(expected = RuntimeException.class)
	public void blockingFirstError() {
		Flux.error(new RuntimeException("test"))
		    .publishOn(scheduler)
		    .blockFirst();
	}

	@Test(expected = RuntimeException.class)
	public void blockingLastError() {
		Flux.error(new RuntimeException("test"))
		    .publishOn(scheduler)
		    .blockLast();
	}

{'fraction_non_alphanumeric': 0.11200298674631323, 'fraction_numerical': 0.014000373343289154, 'mean_word_length': 3.822682268226823, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1083584', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1590, 'n_words': 410}