@Test public void testServer() throws Exception { try (Store store = new Store(folder.newFolder()); CacheServer server = new CacheServer(store, REVISION)) { addInitialFilesToStore(store); store.save(); server.start(); try (Store store2 = new Store(folder.newFolder()); CacheClient client = new CacheClient(store2, HOST, REVISION)) { client.connect(); client.handshake().get(); client.download(); Index index = store2.findIndex(0); Archive archive = index.getArchive(0); FileData[] files = archive.getFileData(); FileData file = files[0]; assertEquals(7, file.getNameHash()); Storage storage = store2.getStorage(); byte[] data = storage.loadArchive(archive); data = archive.decompress(data); assertArrayEquals("test".getBytes(), data); assertEquals(store.getIndexes().get(0).getArchive(0).getCrc(), archive.getCrc()); } } }
public void start() { ServerBootstrap b = new ServerBootstrap(); b.group(group) .channel(NioServerSocketChannel.class) .option(ChannelOption.TCP_NODELAY, true) .childHandler(new CacheServerInitializer(this)); ChannelFuture f = b.bind(PORT).syncUninterruptibly(); channel = f.channel(); logger.info("Server is now listening on {}", PORT); }
CacheServer implements AutoCloseable { public void start() { ServerBootstrap b = new ServerBootstrap(); b.group(group) .channel(NioServerSocketChannel.class) .option(ChannelOption.TCP_NODELAY, true) .childHandler(new CacheServerInitializer(this)); ChannelFuture f = b.bind(PORT).syncUninterruptibly(); channel = f.channel(); logger.info("Server is now listening on {}", PORT); } }
CacheServer implements AutoCloseable { public void start() { ServerBootstrap b = new ServerBootstrap(); b.group(group) .channel(NioServerSocketChannel.class) .option(ChannelOption.TCP_NODELAY, true) .childHandler(new CacheServerInitializer(this)); ChannelFuture f = b.bind(PORT).syncUninterruptibly(); channel = f.channel(); logger.info("Server is now listening on {}", PORT); } CacheServer(Store store, int revision); }
CacheServer implements AutoCloseable { public void start() { ServerBootstrap b = new ServerBootstrap(); b.group(group) .channel(NioServerSocketChannel.class) .option(ChannelOption.TCP_NODELAY, true) .childHandler(new CacheServerInitializer(this)); ChannelFuture f = b.bind(PORT).syncUninterruptibly(); channel = f.channel(); logger.info("Server is now listening on {}", PORT); } CacheServer(Store store, int revision); void start(); void waitForClose(); @Override void close(); int getRevision(); Store getStore(); }
CacheServer implements AutoCloseable { public void start() { ServerBootstrap b = new ServerBootstrap(); b.group(group) .channel(NioServerSocketChannel.class) .option(ChannelOption.TCP_NODELAY, true) .childHandler(new CacheServerInitializer(this)); ChannelFuture f = b.bind(PORT).syncUninterruptibly(); channel = f.channel(); logger.info("Server is now listening on {}", PORT); } CacheServer(Store store, int revision); void start(); void waitForClose(); @Override void close(); int getRevision(); Store getStore();  }