-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add preliminary PublishPeersChannelHandlerTest (currently disabled)
- Loading branch information
1 parent
9cd7a9c
commit c9d1a90
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
.../test/java/org/unigrid/hedgehog/model/network/handler/PublishPeersChannelHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
Unigrid Hedgehog | ||
Copyright © 2021-2023 The Unigrid Foundation, UGD Software AB | ||
This program is free software: you can redistribute it and/or modify it under the terms of the | ||
addended GNU Affero General Public License as published by the The Unigrid Foundation and | ||
the Free Software Foundation, version 3 of the License (see COPYING and COPYING.addendum). | ||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License and the addendum for more details. | ||
You should have received an addended copy of the GNU Affero General Public License with this program. | ||
If not, see <http://www.gnu.org/licenses/> and <https://github.com/unigrid-project/hedgehog>. | ||
*/ | ||
|
||
package org.unigrid.hedgehog.model.network.handler; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import lombok.SneakyThrows; | ||
import mockit.Mocked; | ||
import mockit.Tested; | ||
import net.jqwik.api.Example; | ||
import net.jqwik.api.ForAll; | ||
import net.jqwik.api.constraints.ByteRange; | ||
import net.jqwik.api.Property; | ||
import static org.awaitility.Awaitility.await; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
import org.unigrid.hedgehog.client.P2PClient; | ||
import org.unigrid.hedgehog.model.network.packet.Ping; | ||
import org.unigrid.hedgehog.model.network.initializer.RegisterQuicChannelInitializer; | ||
import org.unigrid.hedgehog.model.network.packet.PublishPeers; | ||
import org.unigrid.hedgehog.model.network.schedule.PingSchedule; | ||
import org.unigrid.hedgehog.server.TestServer; | ||
|
||
public class PublishPeersChannelHandler extends BaseHandlerTest<PublishPeers, PublishPeersChannelHandler> { | ||
public PublishPeersChannelHandler() { | ||
super(PublishPeersChannelHandler.class); | ||
} | ||
|
||
//@Property(tries = 50) | ||
public void shoulBeAbleToPingNetwork(@ForAll("provideTestServers") List<TestServer> servers, | ||
@ForAll @ByteRange(min = 3, max = 5) byte pingsPerServer, | ||
@Mocked PingSchedule pingSchedule) throws Exception { | ||
|
||
final AtomicInteger invocations = new AtomicInteger(); | ||
int expectedInvocations = 0; | ||
|
||
setChannelCallback(Optional.of((ctx, ping) -> { | ||
/* Only count triggers on the server-side */ | ||
if (RegisterQuicChannelInitializer.Type.SERVER.is(ctx.channel())) { | ||
invocations.incrementAndGet(); | ||
} | ||
})); | ||
|
||
for (TestServer server : servers) { | ||
final String host = server.getP2p().getHostName(); | ||
final int port = server.getP2p().getPort(); | ||
final P2PClient client = new P2PClient(host, port); | ||
|
||
for (int i = 0; i < pingsPerServer; i++) { | ||
client.send(Ping.builder().build()); | ||
expectedInvocations++; | ||
} | ||
|
||
await().untilAtomic(invocations, is(expectedInvocations)); | ||
client.closeDirty(); | ||
} | ||
|
||
await().untilAtomic(invocations, is(expectedInvocations)); | ||
} | ||
|
||
@Example | ||
@SneakyThrows | ||
public void shouldSetResponseFlagOnResponse(@Mocked ChannelHandlerContext context, | ||
@Tested PublishPeersChannelHandler handler) { | ||
|
||
/*final Ping ping = PublishPeers.builder(). | ||
assertThat(ping.getNanoTime(), not(0)); | ||
assertThat(ping.isResponse(), is(false)); | ||
handler.typedChannelRead(context, ping); | ||
assertThat(ping.isResponse(), is(true));*/ | ||
} | ||
} |