HivePartitionManager { public Optional<Partition> addPartition( String tableName, List<String> partitionValues, String location, Map<String, String> parameters) throws MetaStoreException { try { URI resolvedLocation = locationResolver.resolveLocation(location, false); Partition partition = newHivePartition(tableName, partitionValues, resolvedLocation.toString(), parameters); partition = metaStoreClient.add_partition(partition); return Optional.of(partition); } catch (AlreadyExistsException e) { return Optional.empty(); } catch (TException e) { throw new MetaStoreException(e); } }  Optional<Partition> addPartition(
      String tableName,
      List<String> partitionValues,
      String location,
      Map<String, String> parameters); Optional<Partition> addPartition(String tableName, List<String> partitionValues, String location); void dropPartition(String tableName, List<String> partitionValues);  }
@Test public void addPartition() throws Exception { doReturn(addedPartition).when(metaStoreClient).add_partition(any()); doReturn(URI.create("resolved/location")).when(locationResolver).resolveLocation(LOCATION, false); doReturn(Instant.ofEpochSecond(1526462225L)).when(clock).instant(); Partition result = underTest.addPartition(TABLE, PARTITION_VALUES, LOCATION).get(); ArgumentCaptor<Partition> captor = ArgumentCaptor.forClass(Partition.class); verify(metaStoreClient).add_partition(captor.capture()); Partition partition = captor.getValue(); assertThat(partition.getParameters().get("data-highway.version"), is(DataHighwayVersion.VERSION)); assertThat(partition.getParameters().get("data-highway.last-revision"), is("2018-05-16T09:17:05Z")); assertThat(partition.getSd().getLocation(), is("resolved/location")); assertThat(result, is(addedPartition)); }
@Test(expected = MetaStoreException.class) public void addPartition_shouldWrapTException() throws Exception { doThrow(TException.class).when(metaStoreClient).add_partition(any()); doReturn(URI.create("resolved/location")).when(locationResolver).resolveLocation(LOCATION, false); doReturn(Instant.ofEpochSecond(1526462225L)).when(clock).instant(); underTest.addPartition(TABLE, PARTITION_VALUES, LOCATION); }
@Test public void addPartition_shouldIgnoreAlreadyExistsException() throws Exception { doThrow(AlreadyExistsException.class).when(metaStoreClient).add_partition(any()); doReturn(URI.create("resolved/location")).when(locationResolver).resolveLocation(LOCATION, false); doReturn(Instant.ofEpochSecond(1526462225L)).when(clock).instant(); Optional<Partition> result = underTest.addPartition(TABLE, PARTITION_VALUES, LOCATION); assertThat(result.isPresent(), is(false)); }