@Override public void stop() { getLifecycleProcessor().stop(); publishEvent(new ContextStoppedEvent(this)); }
@Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextStartedEvent) { this.context = ((ContextStartedEvent) event).getApplicationContext(); this.startedCount++; } else if (event instanceof ContextStoppedEvent) { this.context = ((ContextStoppedEvent) event).getApplicationContext(); this.stoppedCount++; } }
@Override public void stop() { getLifecycleProcessor().stop(); publishEvent(new ContextStoppedEvent(this)); }
@Override public void onApplicationEvent(ContextStoppedEvent event) { if (event.getApplicationContext().equals(this.applicationContext)) { reset(); } }
@Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void testResetTx() throws Exception { final Producer producer = mock(Producer.class); ApplicationContext ctx = mock(ApplicationContext.class); DefaultKafkaProducerFactory pf = new DefaultKafkaProducerFactory(new HashMap<>()) { @Override protected Producer createTransactionalProducer() { producer.initTransactions(); BlockingQueue<Producer> cache = getCache(); Producer cached = cache.poll(); return cached == null ? new CloseSafeProducer(producer, cache) : cached; } }; pf.setApplicationContext(ctx); pf.setTransactionIdPrefix("foo"); Producer aProducer = pf.createProducer(); assertThat(aProducer).isNotNull(); aProducer.close(); assertThat(KafkaTestUtils.getPropertyValue(pf, "producer")).isNull(); Queue cache = KafkaTestUtils.getPropertyValue(pf, "cache", Queue.class); assertThat(cache.size()).isEqualTo(1); pf.onApplicationEvent(new ContextStoppedEvent(ctx)); assertThat(cache.size()).isEqualTo(0); }
public void stop() { getLifecycleProcessor().stop(); publishEvent(new ContextStoppedEvent(this)); }
@Override public void stop() { getLifecycleProcessor().stop(); publishEvent(new ContextStoppedEvent(this)); }