Skip to content

Commit

Permalink
Fix existing test failure cases
Browse files Browse the repository at this point in the history
  • Loading branch information
flaming-archer committed Apr 6, 2024
1 parent e7da34f commit b2638c3
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2016-2021 Expedia, Inc.
* Copyright (C) 2016-2024 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -72,7 +72,7 @@ public void nullDatabasePrefix() {

@Test
public void toJson() throws Exception {
String expected = "{\"accessControlType\":\"READ_ONLY\",\"connectionType\":\"DIRECT\",\"databaseNameMapping\":{},\"databasePrefix\":\"name_\",\"federationType\":\"FEDERATED\",\"hiveMetastoreFilterHook\":null,\"latency\":0,\"mappedDatabases\":null,\"mappedTables\":null,\"metastoreTunnel\":null,\"name\":\"name\",\"remoteMetaStoreUris\":\"uri\",\"status\":\"UNKNOWN\",\"writableDatabaseWhiteList\":[]}";
String expected = "{\"accessControlType\":\"READ_ONLY\",\"connectionType\":\"DIRECT\",\"databaseNameMapping\":{},\"databasePrefix\":\"name_\",\"federationType\":\"FEDERATED\",\"hiveMetastoreFilterHook\":null,\"impersonationEnabled\":false,\"latency\":0,\"mappedDatabases\":null,\"mappedTables\":null,\"metastoreTunnel\":null,\"name\":\"name\",\"remoteMetaStoreUris\":\"uri\",\"status\":\"UNKNOWN\",\"writableDatabaseWhiteList\":[]}";
ObjectMapper mapper = new ObjectMapper();
// Sorting to get deterministic test behaviour
mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2016-2021 Expedia, Inc.
* Copyright (C) 2016-2024 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -89,7 +89,7 @@ public void nonEmptyDatabasePrefix() {

@Test
public void toJson() throws Exception {
String expected = "{\"accessControlType\":\"READ_ONLY\",\"connectionType\":\"DIRECT\",\"databaseNameMapping\":{},\"databasePrefix\":\"\",\"federationType\":\"PRIMARY\",\"hiveMetastoreFilterHook\":null,\"latency\":0,\"mappedDatabases\":null,\"mappedTables\":null,\"metastoreTunnel\":null,\"name\":\"name\",\"remoteMetaStoreUris\":\"uri\",\"status\":\"UNKNOWN\",\"writableDatabaseWhiteList\":[]}";
String expected = "{\"accessControlType\":\"READ_ONLY\",\"connectionType\":\"DIRECT\",\"databaseNameMapping\":{},\"databasePrefix\":\"\",\"federationType\":\"PRIMARY\",\"hiveMetastoreFilterHook\":null,\"impersonationEnabled\":false,\"latency\":0,\"mappedDatabases\":null,\"mappedTables\":null,\"metastoreTunnel\":null,\"name\":\"name\",\"remoteMetaStoreUris\":\"uri\",\"status\":\"UNKNOWN\",\"writableDatabaseWhiteList\":[]}";
ObjectMapper mapper = new ObjectMapper();
// Sorting to get deterministic test behaviour
mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@

import lombok.extern.log4j.Log4j2;

import com.google.common.annotations.VisibleForTesting;

import com.hotels.bdp.waggledance.conf.WaggleDanceConfiguration;
import com.hotels.bdp.waggledance.util.SaslHelper;
import com.hotels.bdp.waggledance.util.SaslHelper.SaslServerAndMDT;
Expand Down Expand Up @@ -335,6 +337,12 @@ static String getIPAddress() {
return null;
}

@VisibleForTesting
public static void setSaslServerAndMDT(
SaslServerAndMDT saslServerAndMDT) {
MetaStoreProxyServer.saslServerAndMDT = saslServerAndMDT;
}

public static SaslServerAndMDT getSaslServerAndMDT() {
return saslServerAndMDT;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2016-2021 Expedia, Inc.
* Copyright (C) 2016-2024 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -214,31 +214,36 @@ public void saveFederationWriteFederations() throws Exception {
storage.insert(newFederatedInstance);
storage.saveFederation();
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
assertThat(lines.size(), is(24));
assertThat(lines.get(0), is("primary-meta-store:"));
assertThat(lines.get(1), is(" access-control-type: READ_ONLY"));
assertThat(lines.get(2), is(" database-prefix: ''"));
assertThat(lines.get(3), is(" latency: 0"));
assertThat(lines.get(4), is(" name: hcom_1"));
assertThat(lines.get(5), is(" remote-meta-store-uris: thrift://localhost:19083"));
assertThat(lines.get(6), is("federated-meta-stores:"));
assertThat(lines.get(7), is("- access-control-type: READ_ONLY"));
assertThat(lines.get(8), is(" database-name-mapping: {}"));
assertThat(lines.get(9), is(" database-prefix: hcom_2_"));
assertThat(lines.get(10), is(" hive-metastore-filter-hook: filter.hook.class"));
assertThat(lines.get(11), is(" latency: 0"));
assertThat(lines.get(12), is(" mapped-databases:"));
assertThat(lines.get(13), is(" - db1"));
assertThat(lines.get(14), is(" - db2"));
assertThat(lines.get(15), is(" mapped-tables:"));
assertThat(lines.get(16), is(" - database: db1"));
assertThat(lines.get(17), is(" mapped-tables:"));
assertThat(lines.get(18), is(" - tbl1"));
assertThat(lines.get(19), is(" - database: db2"));
assertThat(lines.get(20), is(" mapped-tables:"));
assertThat(lines.get(21), is(" - tbl2"));
assertThat(lines.get(22), is(" name: hcom_2"));
assertThat(lines.get(23), is(" remote-meta-store-uris: thrift://localhost:29083"));
assertThat(lines.size(), is(26));
int i = 0;
while (i < 26) {
assertThat(lines.get(i++), is("primary-meta-store:"));
assertThat(lines.get(i), is(" access-control-type: READ_ONLY"));
assertThat(lines.get(i++), is(" database-prefix: ''"));
assertThat(lines.get(i++), is(" latency: 0"));
assertThat(lines.get(i++), is(" impersonation-enabled: false"));
assertThat(lines.get(i++), is(" name: hcom_1"));
assertThat(lines.get(i++), is(" remote-meta-store-uris: thrift://localhost:19083"));
assertThat(lines.get(i++), is("federated-meta-stores:"));
assertThat(lines.get(i++), is("- access-control-type: READ_ONLY"));
assertThat(lines.get(i++), is(" database-name-mapping: {}"));
assertThat(lines.get(i++), is(" database-prefix: hcom_2_"));
assertThat(lines.get(i++), is(" hive-metastore-filter-hook: filter.hook.class"));
assertThat(lines.get(i++), is(" latency: 0"));
assertThat(lines.get(i++), is(" impersonation-enabled: false"));
assertThat(lines.get(i++), is(" mapped-databases:"));
assertThat(lines.get(i++), is(" - db1"));
assertThat(lines.get(i++), is(" - db2"));
assertThat(lines.get(i++), is(" mapped-tables:"));
assertThat(lines.get(i++), is(" - database: db1"));
assertThat(lines.get(i++), is(" mapped-tables:"));
assertThat(lines.get(i++), is(" - tbl1"));
assertThat(lines.get(i++), is(" - database: db2"));
assertThat(lines.get(i++), is(" mapped-tables:"));
assertThat(lines.get(i++), is(" - tbl2"));
assertThat(lines.get(i++), is(" name: hcom_2"));
assertThat(lines.get(i++), is(" remote-meta-store-uris: thrift://localhost:29083"));
}
}

@Test
Expand Down Expand Up @@ -296,30 +301,35 @@ public void savePrimaryWriteFederations() throws Exception {
storage.insert(newFederatedInstance("hcom_2", "thrift://localhost:29083"));
storage.saveFederation();
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
assertThat(lines.size(), is(23));
assertThat(lines.get(0), is("primary-meta-store:"));
assertThat(lines.get(1), is(" access-control-type: READ_ONLY"));
assertThat(lines.get(2), is(" database-prefix: ''"));
assertThat(lines.get(3), is(" latency: 0"));
assertThat(lines.get(4), is(" mapped-databases:"));
assertThat(lines.get(5), is(" - db1"));
assertThat(lines.get(6), is(" - db2"));
assertThat(lines.get(7), is(" mapped-tables:"));
assertThat(lines.get(8), is(" - database: db1"));
assertThat(lines.get(9), is(" mapped-tables:"));
assertThat(lines.get(10), is(" - tbl1"));
assertThat(lines.get(11), is(" - database: db2"));
assertThat(lines.get(12), is(" mapped-tables:"));
assertThat(lines.get(13), is(" - tbl2"));
assertThat(lines.get(14), is(" name: hcom_1"));
assertThat(lines.get(15), is(" remote-meta-store-uris: thrift://localhost:19083"));
assertThat(lines.get(16), is("federated-meta-stores:"));
assertThat(lines.get(17), is("- access-control-type: READ_ONLY"));
assertThat(lines.get(18), is(" database-name-mapping: {}"));
assertThat(lines.get(19), is(" database-prefix: hcom_2_"));
assertThat(lines.get(20), is(" latency: 0"));
assertThat(lines.get(21), is(" name: hcom_2"));
assertThat(lines.get(22), is(" remote-meta-store-uris: thrift://localhost:29083"));
assertThat(lines.size(), is(25));
int i = 0;
while (i < 25) {
assertThat(lines.get(i++), is("primary-meta-store:"));
assertThat(lines.get(i++), is(" access-control-type: READ_ONLY"));
assertThat(lines.get(i++), is(" database-prefix: ''"));
assertThat(lines.get(i++), is(" impersonation-enabled: false"));
assertThat(lines.get(i++), is(" latency: 0"));
assertThat(lines.get(i++), is(" mapped-databases:"));
assertThat(lines.get(i++), is(" - db1"));
assertThat(lines.get(i++), is(" - db2"));
assertThat(lines.get(i++), is(" mapped-tables:"));
assertThat(lines.get(i++), is(" - database: db1"));
assertThat(lines.get(i++), is(" mapped-tables:"));
assertThat(lines.get(i++), is(" - tbl1"));
assertThat(lines.get(i++), is(" - database: db2"));
assertThat(lines.get(i++), is(" mapped-tables:"));
assertThat(lines.get(i++), is(" - tbl2"));
assertThat(lines.get(i++), is(" name: hcom_1"));
assertThat(lines.get(i++), is(" remote-meta-store-uris: thrift://localhost:19083"));
assertThat(lines.get(i++), is("federated-meta-stores:"));
assertThat(lines.get(i++), is("- access-control-type: READ_ONLY"));
assertThat(lines.get(i++), is(" database-name-mapping: {}"));
assertThat(lines.get(i++), is(" database-prefix: hcom_2_"));
assertThat(lines.get(i++), is(" impersonation-enabled: false"));
assertThat(lines.get(i++), is(" latency: 0"));
assertThat(lines.get(i++), is(" name: hcom_2"));
assertThat(lines.get(i++), is(" remote-meta-store-uris: thrift://localhost:29083"));
}
}

private PrimaryMetaStore newPrimaryInstance(String name, String remoteMetaStoreUris) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -211,6 +212,7 @@
import org.apache.hadoop.hive.metastore.api.WMGetTriggersForResourePlanResponse;
import org.apache.hadoop.hive.metastore.api.WMValidateResourcePlanRequest;
import org.apache.hadoop.hive.metastore.api.WMValidateResourcePlanResponse;
import org.apache.hadoop.hive.metastore.security.MetastoreDelegationTokenManager;
import org.apache.thrift.TException;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -227,6 +229,7 @@
import com.hotels.bdp.waggledance.mapping.service.MappingEventListener;
import com.hotels.bdp.waggledance.mapping.service.PanopticOperationHandler;
import com.hotels.bdp.waggledance.mapping.service.impl.NotifyingFederationService;
import com.hotels.bdp.waggledance.util.SaslHelper.SaslServerAndMDT;

@RunWith(MockitoJUnitRunner.class)
public class FederatedHMSHandlerTest {
Expand All @@ -244,6 +247,9 @@ public class FederatedHMSHandlerTest {
private @Mock DatabaseMapping primaryMapping;
private @Mock Iface primaryClient;
private @Mock WaggleDanceConfiguration waggleDanceConfiguration;
private @Mock SaslServerAndMDT saslServerAndMDT;
private @Mock MetastoreDelegationTokenManager metastoreDelegationTokenManager;
private @Mock MetaStoreProxyServer metaStoreProxyServer;

private FederatedHMSHandler handler;

Expand Down Expand Up @@ -1518,25 +1524,32 @@ public void grant_revoke_privileges() throws TException {
}

@Test
public void get_delegation_token() throws TException {
public void get_delegation_token() throws TException, IOException, InterruptedException {
String expected = "expected";
when(primaryClient.get_delegation_token("owner", "kerberos_principal")).thenReturn(expected);
MetaStoreProxyServer.setSaslServerAndMDT(saslServerAndMDT);
when(saslServerAndMDT.getDelegationTokenManager()).thenReturn(metastoreDelegationTokenManager);
when(metastoreDelegationTokenManager.getDelegationToken("owner", "kerberos_principal",
null)).thenReturn(expected);
String result = handler.get_delegation_token("owner", "kerberos_principal");
assertThat(result, is(expected));
}

@Test
public void renew_delegation_token() throws TException {
public void renew_delegation_token() throws TException, IOException {
long expected = 10L;
when(primaryClient.renew_delegation_token("token")).thenReturn(expected);
MetaStoreProxyServer.setSaslServerAndMDT(saslServerAndMDT);
when(saslServerAndMDT.getDelegationTokenManager()).thenReturn(metastoreDelegationTokenManager);
when(metastoreDelegationTokenManager.renewDelegationToken("token")).thenReturn(expected);
long result = handler.renew_delegation_token("token");
assertThat(result, is(expected));
}

@Test
public void cancel_delegation_token() throws TException {
public void cancel_delegation_token() throws TException, IOException {
MetaStoreProxyServer.setSaslServerAndMDT(saslServerAndMDT);
when(saslServerAndMDT.getDelegationTokenManager()).thenReturn(metastoreDelegationTokenManager);
handler.cancel_delegation_token("token");
verify(primaryClient).cancel_delegation_token("token");
verify(metastoreDelegationTokenManager).cancelDelegationToken("token");
}

@Test
Expand Down

0 comments on commit b2638c3

Please sign in to comment.