@Test
    public void testOfflineClient() {
        System.out.println("offlineClient");
        try {
            final Counter counter = new Counter();
            final int multiplier = 3;

            final AssignmentListener al = new AssignmentListener() {
                @Override
                public void receiveTask(Assignment task) {
                    try {
                        Object tsk = task.getTask();

                        if (!(tsk instanceof Integer)) {
                            fail("Illegal task received");
                        }

                        Integer count = (Integer) tsk;

                        synchronized (task) {
                            task.wait(count);
                        }

                        task.submitResult(multiplier * count);
                    } catch (ConnectionException ex) {
                        fail("Connection to server failed - " + ex);
                    } catch (InterruptedException ex) {
                        fail("Waiting has been interrupted - " + ex);
                    }
                }

                @Override
                public void cancelTask(Assignment task) {
                    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                }
            };

            c.setAssignmentListener(al);

            final Client failingClient = ClientImpl.initNewClient(5254);
            try {
                failingClient.registerToServer(GlobalConstants.IP_LOOPBACK);
            } catch (ConnectionException ex) {
                fail("Failed to connect client to server - " + ex);
            }

            failingClient.setAssignmentListener(al);

            int totalCount = 0, val;
            Random rnd = new Random();
            final int jobCount = rnd.nextInt(5) + 5;
            Set<Job> jobs = new HashSet<Job>(jobCount);
            for (int i = 0; i < jobCount; i++) {
                val = (rnd.nextInt(4) + 1) * 10;
                totalCount += multiplier * val;
                jobs.add(s.submitJob(val));
            }

            // client goes offline
            try {
                synchronized (this) {
                    this.wait(totalCount / 4);
                }
                failingClient.stopService();
            } catch (InterruptedException ex) {
                fail("Failed to wait before client goes offline - " + ex);
            }

            s.getJobManager().waitForAllJobs();

            for (Job j : jobs) {
                counter.add((Integer) j.getResult(true));
            }

            assertEquals(totalCount, counter.getCount());
        } catch (IOException ex) {
            fail("Failed to initialize client - " + ex);
        }
    }