@Test public void testNetconfReadOnlyTransaction_NoNetconfException() { when(dataBroker.newReadOnlyTransaction()).thenThrow(RuntimeException.class); Optional<ReadOnlyTransaction> newRtx = NetconfTransactionCreator.netconfReadOnlyTransaction(dataBroker); assertEquals(false, newRtx.isPresent()); verify(dataBroker, times(1)).newReadOnlyTransaction(); }
public static Optional<ReadOnlyTransaction> netconfReadOnlyTransaction(DataBroker mountpoint) { int attempt = 0; do { try { return Optional.ofNullable(mountpoint.newReadOnlyTransaction()); } catch (RuntimeException e) { final Optional<Throwable> optionalCause = Optional.ofNullable(e.getCause()); final Optional<Class> optionalCauseClass = optionalCause.map(Throwable::getClass); if (optionalCauseClass.isPresent() && optionalCauseClass.get().equals(NetconfDocumentedException.class)) { attempt++; LOG.warn("NetconfDocumentedException thrown, retrying ({})...", attempt); try { Thread.sleep(timeout); } catch (InterruptedException i) { LOG.error("Thread interrupted while waiting ... {} ", i); } } else { LOG.error("Runtime exception ... {}", e.getMessage(), e); return Optional.empty(); } } } while (attempt <= 5); LOG.error("Maximum number of attempts reached"); return Optional.empty(); }
NetconfTransactionCreator { public static Optional<ReadOnlyTransaction> netconfReadOnlyTransaction(DataBroker mountpoint) { int attempt = 0; do { try { return Optional.ofNullable(mountpoint.newReadOnlyTransaction()); } catch (RuntimeException e) { final Optional<Throwable> optionalCause = Optional.ofNullable(e.getCause()); final Optional<Class> optionalCauseClass = optionalCause.map(Throwable::getClass); if (optionalCauseClass.isPresent() && optionalCauseClass.get().equals(NetconfDocumentedException.class)) { attempt++; LOG.warn("NetconfDocumentedException thrown, retrying ({})...", attempt); try { Thread.sleep(timeout); } catch (InterruptedException i) { LOG.error("Thread interrupted while waiting ... {} ", i); } } else { LOG.error("Runtime exception ... {}", e.getMessage(), e); return Optional.empty(); } } } while (attempt <= 5); LOG.error("Maximum number of attempts reached"); return Optional.empty(); } }
NetconfTransactionCreator { public static Optional<ReadOnlyTransaction> netconfReadOnlyTransaction(DataBroker mountpoint) { int attempt = 0; do { try { return Optional.ofNullable(mountpoint.newReadOnlyTransaction()); } catch (RuntimeException e) { final Optional<Throwable> optionalCause = Optional.ofNullable(e.getCause()); final Optional<Class> optionalCauseClass = optionalCause.map(Throwable::getClass); if (optionalCauseClass.isPresent() && optionalCauseClass.get().equals(NetconfDocumentedException.class)) { attempt++; LOG.warn("NetconfDocumentedException thrown, retrying ({})...", attempt); try { Thread.sleep(timeout); } catch (InterruptedException i) { LOG.error("Thread interrupted while waiting ... {} ", i); } } else { LOG.error("Runtime exception ... {}", e.getMessage(), e); return Optional.empty(); } } } while (attempt <= 5); LOG.error("Maximum number of attempts reached"); return Optional.empty(); } private  NetconfTransactionCreator(); }
NetconfTransactionCreator { public static Optional<ReadOnlyTransaction> netconfReadOnlyTransaction(DataBroker mountpoint) { int attempt = 0; do { try { return Optional.ofNullable(mountpoint.newReadOnlyTransaction()); } catch (RuntimeException e) { final Optional<Throwable> optionalCause = Optional.ofNullable(e.getCause()); final Optional<Class> optionalCauseClass = optionalCause.map(Throwable::getClass); if (optionalCauseClass.isPresent() && optionalCauseClass.get().equals(NetconfDocumentedException.class)) { attempt++; LOG.warn("NetconfDocumentedException thrown, retrying ({})...", attempt); try { Thread.sleep(timeout); } catch (InterruptedException i) { LOG.error("Thread interrupted while waiting ... {} ", i); } } else { LOG.error("Runtime exception ... {}", e.getMessage(), e); return Optional.empty(); } } } while (attempt <= 5); LOG.error("Maximum number of attempts reached"); return Optional.empty(); } private  NetconfTransactionCreator(); static Optional<ReadOnlyTransaction> netconfReadOnlyTransaction(DataBroker mountpoint); static Optional<WriteTransaction> netconfWriteOnlyTransaction(DataBroker mountpoint); static Optional<ReadWriteTransaction> netconfReadWriteTransaction(DataBroker mountpoint); @VisibleForTesting static void setTimeout(long newTimeout); }
NetconfTransactionCreator { public static Optional<ReadOnlyTransaction> netconfReadOnlyTransaction(DataBroker mountpoint) { int attempt = 0; do { try { return Optional.ofNullable(mountpoint.newReadOnlyTransaction()); } catch (RuntimeException e) { final Optional<Throwable> optionalCause = Optional.ofNullable(e.getCause()); final Optional<Class> optionalCauseClass = optionalCause.map(Throwable::getClass); if (optionalCauseClass.isPresent() && optionalCauseClass.get().equals(NetconfDocumentedException.class)) { attempt++; LOG.warn("NetconfDocumentedException thrown, retrying ({})...", attempt); try { Thread.sleep(timeout); } catch (InterruptedException i) { LOG.error("Thread interrupted while waiting ... {} ", i); } } else { LOG.error("Runtime exception ... {}", e.getMessage(), e); return Optional.empty(); } } } while (attempt <= 5); LOG.error("Maximum number of attempts reached"); return Optional.empty(); } private  NetconfTransactionCreator(); static Optional<ReadOnlyTransaction> netconfReadOnlyTransaction(DataBroker mountpoint); static Optional<WriteTransaction> netconfWriteOnlyTransaction(DataBroker mountpoint); static Optional<ReadWriteTransaction> netconfReadWriteTransaction(DataBroker mountpoint); @VisibleForTesting static void setTimeout(long newTimeout);  }