@Test public void testDirectBroadcastMethod() throws ExecutionException, InterruptedException, ServletException { broadcaster.broadcast("foo", ar).get(); assertEquals(atmosphereHandler.value.get(), new HashSet()); }
public void saveImage(byte[] img) { try { Image image = new Image(img); System.out.println( "SenderName: " + image.senderName + " Filename: " + image.filename + " Message: " + image.message + " Location: " + image.location); if (image.senderName.equals(TabActivity.senderName)) { return; } // checking image is exist in database? mCursor = sqLiteDatabase.rawQuery( "SELECT * FROM " + MyDatabase.TABLE_NAME_PICTURE + " WHERE " + MyDatabase.COL_SENDER_NAME + " = '" + image.senderName + "' AND " + MyDatabase.COL_FILE_NAME + " = '" + image.filename + "' AND " + MyDatabase.COL_MESSAGE + " = '" + image.message + "' AND " + MyDatabase.COL_LOCATION + " = '" + image.location + "'", null); if (mCursor.getCount() == 0) { if (image.imageBytes != null) { String filename = image.filename.substring(0, image.filename.length() - 4); File file = ManageImage.setUpPhotoFile(mAlbumStorageDirFactory, filename); System.out.println("filename :====" + file.getName()); FileOutputStream fileOutputStream = new FileOutputStream(file); fileOutputStream.write(image.getImageBytes()); ManageImage.galleryAddPic(file.getAbsolutePath(), activity); } myDatabase.addToTablePicture( sqLiteDatabase, image.senderName, image.filename, image.message, image.location); Log.d(TAG, "Finished..."); LogFragment.print( "Time recieve: " + getCurrentTimeStamp() + " | From: " + image.senderName + " | Message: " + image.message); // LogFragment.print("Time recieve: " + System.currentTimeMillis() + " | // From: " + image.senderName + " | Message: " + image.message); System.out.println("TestRecieveData: " + System.currentTimeMillis()); final String sentMsg = "Received"; activity.runOnUiThread( new Runnable() { @Override public void run() { NewFeedFragment.updateTable(); Toast.makeText(activity, sentMsg, Toast.LENGTH_LONG).show(); } }); // Sent to other node if (getIPAddressItSelf().equals("0.0.0.0")) { Broadcaster.broadcast(image.getBytes(), ListenerPacket.PORT_PACKET); } } ; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (ImageChunkIncorrectLengthException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }