com.google.common.collect.UnmodifiableIterator Java Examples

The following examples show how to use com.google.common.collect.UnmodifiableIterator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AtlasVirtualFile.java    From atlas with Apache License 2.0 7 votes vote down vote up
protected void fillForMainDexList(Set<DexProgramClass> classes) {
    if (!this.application.mainDexList.isEmpty()) {
        AtlasVirtualFile mainDexFile = (AtlasVirtualFile)this.nameToFileMap.get(0);

        for(UnmodifiableIterator var3 = this.application.mainDexList.iterator(); var3.hasNext(); mainDexFile.commitTransaction()) {
            DexType type = (DexType)var3.next();
            DexClass clazz = this.application.definitionFor(type);
            if (clazz != null && clazz.isProgramClass()) {
                DexProgramClass programClass = (DexProgramClass)clazz;
                mainDexFile.addClass(programClass);
                classes.remove(programClass);
            } else {
                System.out.println("WARNING: Application does not contain `" + type.toSourceString() + "` as referenced in main-dex-list.");
            }
        }

        mainDexFile.throwIfFull(true);
    }

}
 
Example #2
Source File: BlockGenericPipe.java    From Logistics-Pipes-2 with MIT License 6 votes vote down vote up
@Override
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
      {
          if(part.isPresent())
          {
              // This whole thing is subject to change, but should do for now.
              UnmodifiableIterator<String> parts = Models.getParts(part.get());
              if(parts.hasNext())
              {
                  String name = parts.next();
                  // only interested in the root level
                  if(!parts.hasNext() && hidden.contains(name))
                  {
                      return value;
                  }
              }
          }
          return Optional.absent();
      }
 
Example #3
Source File: AliasOrIndex.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the unique alias metadata per concrete index.
 *
 * (note that although alias can point to the same concrete indices, each alias reference may have its own routing
 * and filters)
 */
public Iterable<Tuple<String, AliasMetaData>> getConcreteIndexAndAliasMetaDatas() {
    return new Iterable<Tuple<String, AliasMetaData>>() {
        @Override
        public Iterator<Tuple<String, AliasMetaData>> iterator() {
            return new UnmodifiableIterator<Tuple<String,AliasMetaData>>() {

                int index = 0;

                @Override
                public boolean hasNext() {
                    return index < referenceIndexMetaDatas.size();
                }

                @Override
                public Tuple<String, AliasMetaData> next() {
                    IndexMetaData indexMetaData = referenceIndexMetaDatas.get(index++);
                    return new Tuple<>(indexMetaData.getIndex(), indexMetaData.getAliases().get(aliasName));
                }

            };
        }
    };
}
 
Example #4
Source File: AbstractEventQueryImpl.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public synchronized void addListener ( final EventListener eventListener )
{
    this.listeners.add ( eventListener );

    final UnmodifiableIterator<List<Event>> it = Iterators.partition ( AbstractEventQueryImpl.this.events.iterator (), chunkSize );
    while ( it.hasNext () )
    {
        final List<org.eclipse.scada.ae.Event> chunk = it.next ();
        this.executor.execute ( new Runnable () {

            @Override
            public void run ()
            {
                eventListener.handleEvent ( chunk );
            }
        } );
    }

}
 
Example #5
Source File: RelCollationImpl.java    From Quicksql with MIT License 6 votes vote down vote up
public int compareTo(@Nonnull RelMultipleTrait o) {
  final RelCollationImpl that = (RelCollationImpl) o;
  final UnmodifiableIterator<RelFieldCollation> iterator =
      that.fieldCollations.iterator();
  for (RelFieldCollation f : fieldCollations) {
    if (!iterator.hasNext()) {
      return 1;
    }
    final RelFieldCollation f2 = iterator.next();
    int c = Utilities.compare(f.getFieldIndex(), f2.getFieldIndex());
    if (c != 0) {
      return c;
    }
  }
  return iterator.hasNext() ? -1 : 0;
}
 
Example #6
Source File: HostFileManager.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public Iterator<InetSocketAddress> iterator() {
  return new UnmodifiableIterator<InetSocketAddress>() {
    private final Iterator<Map.Entry<InetAddress,
            Integer>> it = addrs.entries().iterator();

    @Override
    public boolean hasNext() {
      return it.hasNext();
    }

    @Override
    public InetSocketAddress next() {
      Map.Entry<InetAddress, Integer> e = it.next();
      return new InetSocketAddress(e.getKey(), e.getValue());
    }
  };
}
 
Example #7
Source File: CssNode.java    From closure-stylesheets with Apache License 2.0 6 votes vote down vote up
/**
 * This node and the transitive closure of its {@link #parent}s.
 */
public Iterable<CssNode> ancestors() {
  return new Iterable<CssNode>() {
    @Override
    public Iterator<CssNode> iterator() {
      return new UnmodifiableIterator<CssNode>() {

        private CssNode current = CssNode.this;

        @Override
        public boolean hasNext() {
          return current != null;
        }

        @Override
        public CssNode next() {
          CssNode result = current;
          current = current.getParent();
          return result;
        }
      };
    }
  };
}
 
Example #8
Source File: DataStoreJerseyTest.java    From emodb with Apache License 2.0 6 votes vote down vote up
@Test
public void testListTablesRestricted() {
    final TableOptions options = new TableOptionsBuilder().setPlacement("my:placement").build();
    final ImmutableMap<String, Object> template = ImmutableMap.<String, Object>of("key", "value1");
    final TableAvailability availability = new TableAvailability("my:placement", false);
    final DefaultTable a1 = new DefaultTable("a-table-1", options, template, availability);
    final DefaultTable a2 = new DefaultTable("a-table-2", options, template, availability);
    final DefaultTable b1 = new DefaultTable("b-table-1", options, template, availability);
    final DefaultTable b2 = new DefaultTable("b-table-2", options, template, availability);
    final DefaultTable a3 = new DefaultTable("a-table-3", options, template, availability);
    final ImmutableList<Table> tables = ImmutableList.of(a1, a2, b1, b2, a3);

    final UnmodifiableIterator<Table> iterator = tables.iterator();
    //noinspection unchecked
    when(_server.listTables(null, Long.MAX_VALUE)).thenAnswer(invocation -> iterator);

    {
        final Iterator<Table> tableIterator = sorClient(APIKEY_READ_TABLES_A).listTables(null, 3);
        final ImmutableList<Table> result = ImmutableList.copyOf(tableIterator);
        assertEquals(ImmutableList.<Table>of(a1, a2, a3), result);
    }
    verify(_server, times(1)).listTables(null, Long.MAX_VALUE);
}
 
Example #9
Source File: MailDelivrerTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
public void deliverShouldReturnPermanentErrorWhenLimitDNSProblemExceeded() throws Exception {
    Mail mail = FakeMail.builder().name("name").recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build();

    DeliveryRetriesHelper.incrementRetries(mail);
    DeliveryRetriesHelper.incrementRetries(mail);
    DeliveryRetriesHelper.incrementRetries(mail);
    DeliveryRetriesHelper.incrementRetries(mail);

    UnmodifiableIterator<HostAddress> empty = ImmutableList.<HostAddress>of().iterator();
    when(dnsHelper.retrieveHostAddressIterator(MailAddressFixture.JAMES_APACHE_ORG)).thenReturn(empty);

    ExecutionResult executionResult = testee.deliver(mail);

    assertThat(executionResult.getExecutionState()).isEqualTo(ExecutionResult.ExecutionState.PERMANENT_FAILURE);
}
 
Example #10
Source File: MailDelivrerTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
public void deliverShouldTryTwiceOnIOException() throws Exception {
    Mail mail = FakeMail.builder().name("name").recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build();

    UnmodifiableIterator<HostAddress> dnsEntries = ImmutableList.of(
        HOST_ADDRESS_1,
        HOST_ADDRESS_2).iterator();
    when(dnsHelper.retrieveHostAddressIterator(MailAddressFixture.JAMES_APACHE_ORG)).thenReturn(dnsEntries);
    when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(Collection.class), eq(HOST_ADDRESS_1)))
        .thenThrow(new MessagingException("400 : Horrible way to manage Server Return code", new IOException()));
    when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(Collection.class), eq(HOST_ADDRESS_2)))
        .thenReturn(ExecutionResult.success());
    ExecutionResult executionResult = testee.deliver(mail);

    verify(mailDelivrerToHost, times(2)).tryDeliveryToHost(any(Mail.class), any(Collection.class), any(HostAddress.class));
    assertThat(executionResult.getExecutionState()).isEqualTo(ExecutionResult.ExecutionState.SUCCESS);
}
 
Example #11
Source File: MailDelivrerTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
public void deliverShouldAttemptDeliveryOnBothMXIfStillRecipients() throws Exception {
    Mail mail = FakeMail.builder().name("name").recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build();
    Address[] validSent = {};
    Address[] validUnsent = {new InternetAddress(MailAddressFixture.OTHER_AT_JAMES.asString())};
    Address[] invalid = {};
    SendFailedException sfe = new SendFailedException("Message",
        new Exception(),
        validSent,
        validUnsent,
        invalid);

    UnmodifiableIterator<HostAddress> dnsEntries = ImmutableList.of(
        HOST_ADDRESS_1,
        HOST_ADDRESS_2).iterator();
    when(dnsHelper.retrieveHostAddressIterator(MailAddressFixture.JAMES_APACHE_ORG)).thenReturn(dnsEntries);
    when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(Collection.class), any(HostAddress.class)))
        .thenThrow(sfe);
    ExecutionResult executionResult = testee.deliver(mail);

    verify(mailDelivrerToHost, times(2)).tryDeliveryToHost(any(Mail.class), any(Collection.class), any(HostAddress.class));
    assertThat(executionResult.getExecutionState()).isEqualTo(ExecutionResult.ExecutionState.TEMPORARY_FAILURE);
}
 
Example #12
Source File: MailDelivrerTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
public void deliverShouldWorkIfOnlyMX2Valid() throws Exception {
    Mail mail = FakeMail.builder().name("name").recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build();
    Address[] validSent = {};
    Address[] validUnsent = {new InternetAddress(MailAddressFixture.OTHER_AT_JAMES.asString())};
    Address[] invalid = {};
    SendFailedException sfe = new SendFailedException("Message",
        new Exception(),
        validSent,
        validUnsent,
        invalid);

    UnmodifiableIterator<HostAddress> dnsEntries = ImmutableList.of(
        HOST_ADDRESS_1,
        HOST_ADDRESS_2).iterator();
    when(dnsHelper.retrieveHostAddressIterator(MailAddressFixture.JAMES_APACHE_ORG)).thenReturn(dnsEntries);
    when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(Collection.class), eq(HOST_ADDRESS_1)))
        .thenThrow(sfe);
    when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(Collection.class), eq(HOST_ADDRESS_2)))
        .thenReturn(ExecutionResult.success());
    ExecutionResult executionResult = testee.deliver(mail);

    verify(mailDelivrerToHost, times(2)).tryDeliveryToHost(any(Mail.class), any(Collection.class), any(HostAddress.class));
    assertThat(executionResult.getExecutionState()).isEqualTo(ExecutionResult.ExecutionState.SUCCESS);
}
 
Example #13
Source File: ImmutableOffsetMap.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public @NonNull Iterator<Entry<K, V>> iterator() {
    final Iterator<Entry<K, Integer>> it = offsets.entrySet().iterator();
    return new UnmodifiableIterator<Entry<K, V>>() {
        @Override
        public boolean hasNext() {
            return it.hasNext();
        }

        @Override
        public Entry<K, V> next() {
            final Entry<K, Integer> e = it.next();
            return new SimpleImmutableEntry<>(e.getKey(), objects[e.getValue()]);
        }
    };
}
 
Example #14
Source File: SchemaPath.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the list of nodes which need to be traversed to get from this
 * node to the starting point (root for absolute SchemaPaths).
 *
 * @return list of <code>qname</code> instances which represents
 *         path from the schema node towards the root.
 */
public Iterable<QName> getPathTowardsRoot() {
    return () -> new UnmodifiableIterator<>() {
        private SchemaPath current = SchemaPath.this;

        @Override
        public boolean hasNext() {
            return current.parent != null;
        }

        @Override
        public QName next() {
            if (current.parent != null) {
                final QName ret = current.qname;
                current = current.parent;
                return ret;
            }

            throw new NoSuchElementException("No more elements available");
        }
    };
}
 
Example #15
Source File: RelCollationImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
public int compareTo(@Nonnull RelMultipleTrait o) {
  final RelCollationImpl that = (RelCollationImpl) o;
  final UnmodifiableIterator<RelFieldCollation> iterator =
      that.fieldCollations.iterator();
  for (RelFieldCollation f : fieldCollations) {
    if (!iterator.hasNext()) {
      return 1;
    }
    final RelFieldCollation f2 = iterator.next();
    int c = Utilities.compare(f.getFieldIndex(), f2.getFieldIndex());
    if (c != 0) {
      return c;
    }
  }
  return iterator.hasNext() ? -1 : 0;
}
 
Example #16
Source File: RangeList.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Override
public Iterator<Integer> iterator() {
  return new UnmodifiableIterator<Integer>() {
    int cursor = start;

    @Override
    public boolean hasNext() {
      return (step > 0) ? (cursor < stop) : (cursor > stop);
    }

    @Override
    public Integer next() {
      if (!hasNext()) {
        throw new NoSuchElementException();
      }
      int current = cursor;
      cursor += step;
      return current;
    }
  };
}
 
Example #17
Source File: Bug62456849TestDataGenerator.java    From bazel with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
  checkArgument(
      args.length == 2,
      "Usage: %s <input-jar> <output-jar>",
      Bug62456849TestDataGenerator.class.getName());
  Path inputJar = Paths.get(args[0]);
  checkArgument(Files.isRegularFile(inputJar), "The input jar %s is not a file", inputJar);
  Path outputJar = Paths.get(args[1]);

  try (ZipFile inputZip = new ZipFile(inputJar.toFile());
      ZipOutputStream outZip =
          new ZipOutputStream(new BufferedOutputStream(Files.newOutputStream(outputJar)))) {
    for (UnmodifiableIterator<? extends ZipEntry> it =
            Iterators.forEnumeration(inputZip.entries());
        it.hasNext(); ) {
      ZipEntry entry = it.next();
      String entryName = entry.getName();
      byte[] content =
          entryName.endsWith(".class")
              ? convertClass(inputZip, entry)
              : readEntry(inputZip, entry);
      writeToZipFile(outZip, entryName, content);
    }
  }
}
 
Example #18
Source File: PathArgumentListTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public UnmodifiableIterator<PathArgument> iterator() {
    return new UnmodifiableIterator<PathArgument>() {
        @Override
        public boolean hasNext() {
            return false;
        }

        @Override
        public PathArgument next() {
            throw new NoSuchElementException();
        }
    };
}
 
Example #19
Source File: IteratorsTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void toFluxShouldReturnEmptyStreamWhenEmptyIterator() {
    UnmodifiableIterator<String> emptyIterator = ImmutableList.<String>of().iterator();

    Flux<String> actual = Iterators.toFlux(emptyIterator);

    assertThat(actual.count().block()).isEqualTo(0);
}
 
Example #20
Source File: IteratorsTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void toFluxShouldReturnSameContent() {
    UnmodifiableIterator<String> iterator = ImmutableList.of("a", "b", "c").iterator();

    Flux<String> actual = Iterators.toFlux(iterator);

    assertThat(actual.collect(toList()).block()).containsExactly("a", "b", "c");
}
 
Example #21
Source File: ClassPathResultTest.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetClassPathEntries() {
  ImmutableListMultimap<ClassPathEntry, DependencyPath> tree =
      ImmutableListMultimap.of(
          jarA, dependencyPath_A,
          jarB, dependencyPath_B,
          jarA, dependencyPath_A_B_A);

  ClassPathResult result = new ClassPathResult(tree, ImmutableSet.of());

  ImmutableSet<ClassPathEntry> classPathEntries = result.getClassPathEntries("com.google:a:1");
  assertEquals(1, classPathEntries.size());
  UnmodifiableIterator<ClassPathEntry> iterator = classPathEntries.iterator();
  assertEquals(Paths.get("a.jar"), iterator.next().getJar());
}
 
Example #22
Source File: IteratorsTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void toStreamShouldReturnSameContent() {
    //Given
    UnmodifiableIterator<String> iterator = ImmutableList.of("a", "b", "c").iterator();

    //When
    Stream<String> actual = Iterators.toStream(iterator);

    //Then
    assertThat(actual.collect(toList())).containsExactly("a", "b", "c");
}
 
Example #23
Source File: MailDelivrerTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
public void deliverShouldAbortWhenServerErrorSFE() throws Exception {
    Mail mail = FakeMail.builder().name("name").recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build();

    UnmodifiableIterator<HostAddress> dnsEntries = ImmutableList.of(
        HOST_ADDRESS_1,
        HOST_ADDRESS_2).iterator();
    when(dnsHelper.retrieveHostAddressIterator(MailAddressFixture.JAMES_APACHE_ORG)).thenReturn(dnsEntries);
    when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(Collection.class), any(HostAddress.class)))
        .thenThrow(new SMTPSenderFailedException(new InternetAddress(MailAddressFixture.ANY_AT_JAMES.toString()), "command", 505, "Big failure"));
    ExecutionResult executionResult = testee.deliver(mail);

    verify(mailDelivrerToHost, times(1)).tryDeliveryToHost(any(Mail.class), any(Collection.class), any(HostAddress.class));
    assertThat(executionResult.getExecutionState()).isEqualTo(ExecutionResult.ExecutionState.PERMANENT_FAILURE);
}
 
Example #24
Source File: MailDelivrerTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
public void deliverShouldAbortWithTemporaryWhenMessagingExceptionCauseUnknown() throws Exception {
    Mail mail = FakeMail.builder().name("name").recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build();

    UnmodifiableIterator<HostAddress> dnsEntries = ImmutableList.of(
        HOST_ADDRESS_1,
        HOST_ADDRESS_2).iterator();
    when(dnsHelper.retrieveHostAddressIterator(MailAddressFixture.JAMES_APACHE_ORG)).thenReturn(dnsEntries);
    when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(Collection.class), any(HostAddress.class)))
        .thenThrow(new MessagingException("400 : Horrible way to manage Server Return code"));
    ExecutionResult executionResult = testee.deliver(mail);

    verify(mailDelivrerToHost, times(1)).tryDeliveryToHost(any(Mail.class), any(Collection.class), any(HostAddress.class));
    assertThat(executionResult.getExecutionState()).isEqualTo(ExecutionResult.ExecutionState.TEMPORARY_FAILURE);
}
 
Example #25
Source File: MailDelivrerTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
public void deliverShouldAbortWhenServerError() throws Exception {
    Mail mail = FakeMail.builder().name("name").recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build();

    UnmodifiableIterator<HostAddress> dnsEntries = ImmutableList.of(
        HOST_ADDRESS_1,
        HOST_ADDRESS_2).iterator();
    when(dnsHelper.retrieveHostAddressIterator(MailAddressFixture.JAMES_APACHE_ORG)).thenReturn(dnsEntries);
    when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(Collection.class), any(HostAddress.class)))
        .thenThrow(new MessagingException("500 : Horrible way to manage Server Return code"));
    ExecutionResult executionResult = testee.deliver(mail);

    verify(mailDelivrerToHost, times(1)).tryDeliveryToHost(any(Mail.class), any(Collection.class), any(HostAddress.class));
    assertThat(executionResult.getExecutionState()).isEqualTo(ExecutionResult.ExecutionState.PERMANENT_FAILURE);
}
 
Example #26
Source File: MailDelivrerTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
public void deliverShouldWork() throws Exception {
    Mail mail = FakeMail.builder().name("name").recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build();

    UnmodifiableIterator<HostAddress> dnsEntries = ImmutableList.of(
        HOST_ADDRESS_1,
        HOST_ADDRESS_2).iterator();
    when(dnsHelper.retrieveHostAddressIterator(MailAddressFixture.JAMES_APACHE_ORG)).thenReturn(dnsEntries);
    when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(Collection.class), any(HostAddress.class)))
        .thenReturn(ExecutionResult.success());
    ExecutionResult executionResult = testee.deliver(mail);

    verify(mailDelivrerToHost, times(1)).tryDeliveryToHost(any(Mail.class), any(Collection.class), any(HostAddress.class));
    assertThat(executionResult.getExecutionState()).isEqualTo(ExecutionResult.ExecutionState.SUCCESS);
}
 
Example #27
Source File: DocSchemaInfo.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Collection<String> tableNames() {
    // TODO: once we support closing/opening tables change this to concreteIndices()
    // and add  state info to the TableInfo.

    Set<String> tables = new HashSet<>();
    tables.addAll(Collections2.filter(Collections2.transform(
            Arrays.asList(clusterService.state().metaData().concreteAllOpenIndices()), indexToTableName), tablesFilter));

    // Search for partitioned table templates
    UnmodifiableIterator<String> templates = clusterService.state().metaData().getTemplates().keysIt();
    while (templates.hasNext()) {
        String templateName = templates.next();
        if (!PartitionName.isPartition(templateName)) {
            continue;
        }
        try {
            PartitionName partitionName = PartitionName.fromIndexOrTemplate(templateName);
            TableIdent ti = partitionName.tableIdent();
            if (schemaName.equalsIgnoreCase(ti.schema())) {
                tables.add(ti.name());
            }
        } catch (IllegalArgumentException e) {
            // do nothing
        }
    }

    return tables;
}
 
Example #28
Source File: MailDelivrerTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
public void deliverShouldReturnPermanentErrorWhenLimitDNSProblemReached() throws Exception {
    Mail mail = FakeMail.builder().name("name").recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build();
    DeliveryRetriesHelper.incrementRetries(mail);
    DeliveryRetriesHelper.incrementRetries(mail);
    DeliveryRetriesHelper.incrementRetries(mail);

    UnmodifiableIterator<HostAddress> empty = ImmutableList.<HostAddress>of().iterator();
    when(dnsHelper.retrieveHostAddressIterator(MailAddressFixture.JAMES_APACHE_ORG)).thenReturn(empty);

    ExecutionResult executionResult = testee.deliver(mail);

    assertThat(executionResult.getExecutionState()).isEqualTo(ExecutionResult.ExecutionState.PERMANENT_FAILURE);
}
 
Example #29
Source File: MailDelivrerTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
public void deliverShouldReturnTemporaryErrorWhenToleratedDNSProblem() throws Exception {
    Mail mail = FakeMail.builder().name("name").recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build();
    DeliveryRetriesHelper.incrementRetries(mail);

    UnmodifiableIterator<HostAddress> empty = ImmutableList.<HostAddress>of().iterator();
    when(dnsHelper.retrieveHostAddressIterator(MailAddressFixture.JAMES_APACHE_ORG)).thenReturn(empty);

    ExecutionResult executionResult = testee.deliver(mail);

    assertThat(executionResult.getExecutionState()).isEqualTo(ExecutionResult.ExecutionState.TEMPORARY_FAILURE);
}
 
Example #30
Source File: MailDelivrerTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
public void deliverShouldAttemptDeliveryOnlyOnceIfNoMoreValidUnsent() throws Exception {
    Mail mail = FakeMail.builder().name("name").recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build();

    UnmodifiableIterator<HostAddress> dnsEntries = ImmutableList.of(
        HOST_ADDRESS_1,
        HOST_ADDRESS_2).iterator();
    when(dnsHelper.retrieveHostAddressIterator(MailAddressFixture.JAMES_APACHE_ORG)).thenReturn(dnsEntries);
    when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(Collection.class), any(HostAddress.class)))
        .thenThrow(new SendFailedException());
    ExecutionResult executionResult = testee.deliver(mail);

    verify(mailDelivrerToHost, times(1)).tryDeliveryToHost(any(Mail.class), any(Collection.class), any(HostAddress.class));
    assertThat(executionResult.getExecutionState()).isEqualTo(ExecutionResult.ExecutionState.TEMPORARY_FAILURE);
}