### Question:
BasicEventConsumer implements EventConsumer, ServerProxyTrust { public boolean register(final RemoteServiceEventListener listener) { return (register(listener, null)); } BasicEventConsumer(final EventDescriptor edTemplate);  BasicEventConsumer(final RemoteServiceEventListener<?> listener);  BasicEventConsumer(final EventDescriptor edTemplate, final RemoteServiceEventListener<?> listener);  BasicEventConsumer(final EventDescriptor edTemplate,
                              final RemoteServiceEventListener<?> listener,
                              final Configuration config);  BasicEventConsumer(final EventDescriptor edTemplate,
                              final RemoteServiceEventListener<?> listener,
                              final MarshalledObject<?> handback,
                              final Configuration config); void terminate(); boolean register(final RemoteServiceEventListener listener); boolean register(final RemoteServiceEventListener listener, final MarshalledObject handback); boolean deregister(final RemoteServiceEventListener listener); Watch createWatch(final WatchDataSourceRegistry watchRegistry); void destroyWatch(); Watch getWatch(); EventRegistration register(final ServiceItem item); EventRegistration register(final EventProducer eventProducer,
                                      final EventDescriptor eventDesc,
                                      final ServiceID serviceID); Object getEventRegistrationSource(final long eventID); void deregister(final ServiceID serviceID); void deregister(final ServiceID serviceID, final boolean disconnect); void notify(final RemoteEvent rEvent); TrustVerifier getProxyVerifier(); static final String RESPONSE_WATCH; }### Answer:
@Test public void testRegisteringAnEventProducerAndFiringAnEvent() throws Exception { BasicEventConsumer consumer = new BasicEventConsumer(getEventDescriptor()); Listener listener = new Listener(); consumer.register(listener); Producer p = new Producer(); p.createDEH(); ServiceItem serviceItem = createServiceItem(p); EventRegistration eventRegistration = consumer.register(serviceItem); Assert.assertNotNull(eventRegistration); p.fire(); listener.countDown.await(5, TimeUnit.SECONDS); Assert.assertTrue("Expected listener count to be > 0, found: " + listener.counter.get(), listener.counter.get() > 0); }
@Test public void testRegisteringAnEventProducerAndFiringAnEventWithLeaseBeingDropped() throws Exception { BasicEventConsumer consumer = new BasicEventConsumer(getEventDescriptor()); Listener listener = new Listener(); consumer.register(listener); Producer p = new Producer(); p.setLeaseTime(3 * 1000); p.createDEH(); ServiceItem serviceItem = createServiceItem(p); EventRegistration eventRegistration = consumer.register(serviceItem); Assert.assertNotNull(eventRegistration); System.err.println("Waiting 5 seconds for lease to timeout..."); int i = 1; while (i < 50) { Thread.sleep(100); i++; } p.fire(); assertEquals("Should have not been notified, but got: " + listener.counter.get(), 0, listener.counter.get()); }
@Test public void testRegisteringAnEventProducerAndFiringEventsUsingRoundRobin() throws Exception { Producer p = new Producer(); p.createRoundRobin(); ServiceItem serviceItem = createServiceItem(p); BasicEventConsumer consumer1 = new BasicEventConsumer(getEventDescriptor()); Listener listener1 = new Listener(2); consumer1.register(listener1); BasicEventConsumer consumer2 = new BasicEventConsumer(getEventDescriptor()); Listener listener2 = new Listener(2); consumer2.register(listener2); BasicEventConsumer consumer3 = new BasicEventConsumer(getEventDescriptor()); Listener listener3 = new Listener(2); consumer3.register(listener3); Assert.assertNotNull(consumer1.register(serviceItem)); Assert.assertNotNull(consumer2.register(serviceItem)); Assert.assertNotNull(consumer3.register(serviceItem)); for(int i=0; i<6; i++) p.fire(); assertTrue("Should have gotten 2, got " + listener1.counter.get(), listener1.countDown.await(5, TimeUnit.SECONDS)); assertTrue("Should have gotten 2, got " + listener2.counter.get(), listener2.countDown.await(5, TimeUnit.SECONDS)); assertTrue("Should have gotten 2, got " + listener3.counter.get(), listener3.countDown.await(5, TimeUnit.SECONDS)); }