@Test public void whenChannelOverflowsThrowException() throws Exception { assumeThat(policy, is(OverflowPolicy.THROW)); assumeThat(mailboxSize, greaterThan(0)); final Channel<Integer> ch = newChannel(); int i = 0; try { for (i = 0; i < 10; i++) ch.send(i); fail(); } catch (QueueCapacityExceededException e) { System.out.println("i = " + i); } }
@Test public void testBlockingChannelSendingThread() throws Exception { assumeThat(policy, is(OverflowPolicy.BLOCK)); final Channel<Integer> ch = newChannel(); Fiber<Integer> fib = new Fiber<Integer>( fjPool, new SuspendableCallable<Integer>() { @Override public Integer run() throws SuspendExecution, InterruptedException { int i = 0; while (ch.receive() != null) { i++; Fiber.sleep(50); } return i; } }) .start(); for (int i = 0; i < 10; i++) ch.send(i); ch.close(); assertThat(fib.get(), is(10)); }
@Test public void testConnectCancellation() throws Throwable { // Check if the test can be executed or should be skipped because of no network/internet // connection // See https://github.com/netty/netty/issues/1474 boolean badHostTimedOut = true; Socket socket = new Socket(); try { socket.connect(new InetSocketAddress(BAD_HOST, BAD_PORT), 10); } catch (ConnectException e) { badHostTimedOut = false; // is thrown for no route to host when using Socket connect } catch (Exception e) { // ignore } finally { try { socket.close(); } catch (IOException e) { // ignore } } assumeThat( "The connection attempt to " + BAD_HOST + " does not time out.", badHostTimedOut, is(true)); run(); }
@Test public void testUnknownCharset() throws Exception { // We only want to run this test if we can guarantee that the charset _doesn't_ exist in the // system first. Otherwise, we'll just have to ignore this test. assumeThat(Charset.isSupported(UNKNOWN_CHARSET_NAME), is(false)); // We're good to run the test. thrown.expect(ParameterException.class); thrown.expectMessage("unknown encoding"); cc.convert(UNKNOWN_CHARSET_NAME); }
@Test public void durableClientGetsUpdatesFromServerWhileClientWasOffline() { assumeThat(RUN_COUNT.get(), is(equalTo(2))); assertRegionContents(example, 1, 2, 3, 4, 5); // the wait is necessary since the GemFire Server will not have propagated the events in the // durable client's queue // immediately after the client signals ready-for-events in a timely fashion before the test // case // makes the following assertions... waitForRegionEntryEvents(); assertThat(regionCacheListenerEventValues.size(), is(equalTo(2))); assertThat(regionCacheListenerEventValues, is(equalTo(Arrays.asList(4, 5)))); }
@Test public void testPrimitiveChannelClose() throws Exception { assumeThat(mailboxSize, not(equalTo(0))); final IntChannel ch = Channels.newIntChannel(mailboxSize, policy); Fiber fib = new Fiber( "fiber", fjPool, new SuspendableRunnable() { @Override public void run() throws SuspendExecution, InterruptedException { for (int i = 1; i <= 5; i++) { int m = ch.receiveInt(); assertThat(m, is(i)); } try { int m = ch.receiveInt(); fail("m = " + m); } catch (QueueChannel.EOFException e) { } assertTrue(ch.isClosed()); } }) .start(); Thread.sleep(50); ch.send(1); ch.send(2); ch.send(3); ch.send(4); ch.send(5); ch.close(); ch.send(6); ch.send(7); fib.join(); }
@Test public void testBlockingChannelSendingFiber() throws Exception { assumeThat(policy, is(OverflowPolicy.BLOCK)); final Channel<Integer> ch = newChannel(); Fiber<Integer> receiver = new Fiber<Integer>( fjPool, new SuspendableCallable<Integer>() { @Override public Integer run() throws SuspendExecution, InterruptedException { int i = 0; while (ch.receive() != null) { i++; Fiber.sleep(50); } return i; } }) .start(); Fiber<Void> sender = new Fiber<Void>( fjPool, new SuspendableRunnable() { @Override public void run() throws SuspendExecution, InterruptedException { for (int i = 0; i < 10; i++) ch.send(i); ch.close(); } }) .start(); try { assertThat(receiver.get(), is(10)); sender.join(); } catch (Throwable t) { Debug.dumpRecorder("channels.log"); throw t; } }
@Test public void whenChannelClosedThenBlockedSendsComplete() throws Exception { assumeThat(policy, is(OverflowPolicy.BLOCK)); final Channel<Integer> ch = newChannel(); final SuspendableRunnable r = new SuspendableRunnable() { @Override public void run() throws SuspendExecution, InterruptedException { for (int i = 1; i <= 100; i++) { ch.send(i); } } }; Fiber fib1 = new Fiber("fiber", fjPool, r).start(); Fiber fib2 = new Fiber("fiber", fjPool, r).start(); Thread.sleep(500); ch.close(); fib1.join(); fib2.join(); }
@Test public void durableClientGetsInitializedWithDataOnServer() { assumeThat(RUN_COUNT.get(), is(equalTo(1))); assertRegionContents(example, 1, 2, 3); assertThat(regionCacheListenerEventValues.isEmpty(), is(true)); }
@Before public void setUp() { assumeThat(Platform.javaVersion(), greaterOrEqual(JavaVersion.JAVA7)); context_ = new StageContextMock<CodecBuffer>(); }