-
Notifications
You must be signed in to change notification settings - Fork 28k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-31831] Use subclasses for mock in HiveSessionImplSuite
- Loading branch information
Frank Yin
committed
Jul 12, 2020
1 parent
578b90c
commit 9067f21
Showing
3 changed files
with
112 additions
and
23 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...er/src/test/main/java/org/apache/hive/service/cli/operation/GetCatalogsOperationMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hive.service.cli.operation; | ||
|
||
import org.apache.hive.service.cli.HiveSQLException; | ||
import org.apache.hive.service.cli.OperationHandle; | ||
import org.apache.hive.service.cli.session.HiveSession; | ||
import org.apache.hive.service.rpc.thrift.THandleIdentifier; | ||
import org.apache.hive.service.rpc.thrift.TOperationHandle; | ||
import org.apache.hive.service.rpc.thrift.TOperationType; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.UUID; | ||
|
||
public class GetCatalogsOperationMock extends GetCatalogsOperation { | ||
protected GetCatalogsOperationMock(HiveSession parentSession) { | ||
super(parentSession); | ||
} | ||
|
||
@Override | ||
public void runInternal() throws HiveSQLException { | ||
|
||
} | ||
|
||
public OperationHandle getHandle() { | ||
UUID uuid = UUID.randomUUID(); | ||
THandleIdentifier tHandleIdentifier = new THandleIdentifier(); | ||
tHandleIdentifier.setGuid(getByteBufferFromUUID(uuid)); | ||
tHandleIdentifier.setSecret(getByteBufferFromUUID(uuid)); | ||
return new OperationHandle(new TOperationHandle(tHandleIdentifier, TOperationType.GET_TYPE_INFO, false)); | ||
} | ||
|
||
private byte[] getByteBufferFromUUID(UUID uuid) { | ||
ByteBuffer bb = ByteBuffer.wrap(new byte[16]); | ||
bb.putLong(uuid.getMostSignificantBits()); | ||
bb.putLong(uuid.getLeastSignificantBits()); | ||
return bb.array(); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...server/src/test/main/java/org/apache/hive/service/cli/operation/OperationManagerMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hive.service.cli.operation; | ||
|
||
import org.apache.hive.service.cli.HiveSQLException; | ||
import org.apache.hive.service.cli.OperationHandle; | ||
import org.apache.hive.service.cli.session.HiveSession; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class OperationManagerMock extends OperationManager { | ||
private Set<OperationHandle> calledHandles = new HashSet<>(); | ||
|
||
@Override | ||
public GetCatalogsOperation newGetCatalogsOperation(HiveSession parentSession) { | ||
GetCatalogsOperationMock operation = new GetCatalogsOperationMock(parentSession); | ||
try { | ||
Method m = OperationManager.class.getDeclaredMethod("addOperation", Operation.class); | ||
m.setAccessible(true); | ||
m.invoke(this, operation); | ||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return operation; | ||
} | ||
|
||
@Override | ||
public void closeOperation(OperationHandle opHandle) throws HiveSQLException { | ||
calledHandles.add(opHandle); | ||
throw new RuntimeException(); | ||
} | ||
|
||
public Set<OperationHandle> getCalledHandles() { | ||
return calledHandles; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters