You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2020/07/22 02:22:46 UTC

[GitHub] [incubator-pinot] rush00121 opened a new pull request #5726: Adding Test coverage to NoOpPinotCrypt class

rush00121 opened a new pull request #5726:
URL: https://github.com/apache/incubator-pinot/pull/5726


   ## Description
   
   This class did not have any code coverage. Adding a simple test to improve test coverage. 
   Adding test as part of this issue: https://github.com/apache/incubator-pinot/issues/5699
   
   ## Upgrade Notes
   Does this PR prevent a zero down-time upgrade? (Assume upgrade order: Controller, Broker, Server, Minion)
   * [ ] No 
   Does this PR fix a zero-downtime upgrade introduced earlier?
   * [ ] No
   Does this PR otherwise need attention when creating release notes? No
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] rush00121 commented on a change in pull request #5726: Adding Test coverage to NoOpPinotCrypt class

Posted by GitBox <gi...@apache.org>.
rush00121 commented on a change in pull request #5726:
URL: https://github.com/apache/incubator-pinot/pull/5726#discussion_r459270656



##########
File path: pinot-spi/src/test/java/org/apache/pinot/spi/crypt/NoOpPinotCryptTest.java
##########
@@ -0,0 +1,62 @@
+/**
+ * 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.pinot.spi.crypt;
+
+import java.io.File;
+import java.io.IOException;
+import org.apache.commons.io.FileUtils;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class NoOpPinotCryptTest {
+
+  PinotCrypter pinotCrypter;
+  File encryptedFile;
+  File decryptedFile;
+  @BeforeTest
+  public void init() throws IOException {
+    pinotCrypter = new NoOpPinotCrypter();
+    encryptedFile = File.createTempFile("encryptedFile","txt");
+    encryptedFile.deleteOnExit();
+    decryptedFile = File.createTempFile("decryptedFile","txt");
+    decryptedFile.deleteOnExit();
+    FileUtils.write(encryptedFile,"testData");
+  }
+
+  @Test
+  public void testEncryption() throws IOException {
+    pinotCrypter.encrypt(decryptedFile, encryptedFile);
+    Assert.assertTrue(FileUtils.contentEquals(encryptedFile, decryptedFile));
+    decryptedFile = new File("fake");
+    pinotCrypter.encrypt(decryptedFile, encryptedFile);
+    Assert.assertFalse(encryptedFile.exists());

Review comment:
       Sure, makes  sense. I have combined the 2 to a single test. Where we are comparing the srcFile to the final decryptedFile. 
   Also have separated the invalid scenarios to their respective tests
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] mayankshriv commented on a change in pull request #5726: Adding Test coverage to NoOpPinotCrypt class

Posted by GitBox <gi...@apache.org>.
mayankshriv commented on a change in pull request #5726:
URL: https://github.com/apache/incubator-pinot/pull/5726#discussion_r458799963



##########
File path: pinot-spi/src/test/java/org/apache/pinot/spi/crypt/NoOpPinotCryptTest.java
##########
@@ -0,0 +1,62 @@
+/**
+ * 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.pinot.spi.crypt;
+
+import java.io.File;
+import java.io.IOException;
+import org.apache.commons.io.FileUtils;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class NoOpPinotCryptTest {
+
+  PinotCrypter pinotCrypter;
+  File encryptedFile;
+  File decryptedFile;
+  @BeforeTest
+  public void init() throws IOException {
+    pinotCrypter = new NoOpPinotCrypter();
+    encryptedFile = File.createTempFile("encryptedFile","txt");
+    encryptedFile.deleteOnExit();
+    decryptedFile = File.createTempFile("decryptedFile","txt");
+    decryptedFile.deleteOnExit();
+    FileUtils.write(encryptedFile,"testData");
+  }
+
+  @Test
+  public void testEncryption() throws IOException {
+    pinotCrypter.encrypt(decryptedFile, encryptedFile);
+    Assert.assertTrue(FileUtils.contentEquals(encryptedFile, decryptedFile));
+    decryptedFile = new File("fake");
+    pinotCrypter.encrypt(decryptedFile, encryptedFile);
+    Assert.assertFalse(encryptedFile.exists());

Review comment:
       Seems like this test only asserts that an output file is generated. IMHO, a better test would be one that ensures that we get the same original content back after encryption -> decryption. This might mean that we just have one test method as opposed to two tests.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] rush00121 commented on a change in pull request #5726: Adding Test coverage to NoOpPinotCrypt class

Posted by GitBox <gi...@apache.org>.
rush00121 commented on a change in pull request #5726:
URL: https://github.com/apache/incubator-pinot/pull/5726#discussion_r458569882



##########
File path: pinot-spi/src/test/java/org/apache/pinot/spi/crypt/NoOpPinotCryptTest.java
##########
@@ -0,0 +1,63 @@
+/**
+ * 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.pinot.spi.crypt;
+
+import java.io.File;
+import java.io.IOException;
+import org.apache.commons.io.FileUtils;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class NoOpPinotCryptTest {
+
+  PinotCrypter pinotCrypter;
+  File srcFile;
+  File destinationFile;
+  @BeforeTest
+  public void init() throws IOException {
+    pinotCrypter = new NoOpPinotCrypter();
+    srcFile = File.createTempFile("srcFile","txt");

Review comment:
       updated the field names




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] mayankshriv commented on a change in pull request #5726: Adding Test coverage to NoOpPinotCrypt class

Posted by GitBox <gi...@apache.org>.
mayankshriv commented on a change in pull request #5726:
URL: https://github.com/apache/incubator-pinot/pull/5726#discussion_r460409411



##########
File path: pinot-spi/src/test/java/org/apache/pinot/spi/crypt/NoOpPinotCryptTest.java
##########
@@ -0,0 +1,66 @@
+/**
+ * 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.pinot.spi.crypt;
+
+import java.io.File;
+import java.io.IOException;
+import org.apache.commons.io.FileUtils;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class NoOpPinotCryptTest {
+
+  PinotCrypter pinotCrypter;

Review comment:
       As per `Pinot Coding Style`, member variables should be prefixed with `_`. 

##########
File path: pinot-spi/src/test/java/org/apache/pinot/spi/crypt/NoOpPinotCryptTest.java
##########
@@ -0,0 +1,66 @@
+/**
+ * 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.pinot.spi.crypt;
+
+import java.io.File;
+import java.io.IOException;
+import org.apache.commons.io.FileUtils;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class NoOpPinotCryptTest {
+
+  PinotCrypter pinotCrypter;
+  File encryptedFile;
+  File decryptedFile;
+  File srcFile;
+  @BeforeTest
+  public void init() throws IOException {
+    pinotCrypter = new NoOpPinotCrypter();
+    srcFile = File.createTempFile("srcFile","txt");
+    encryptedFile = File.createTempFile("encryptedFile","txt");
+    encryptedFile.deleteOnExit();
+    decryptedFile = File.createTempFile("decryptedFile","txt");
+    decryptedFile.deleteOnExit();
+    FileUtils.write(srcFile,"testData");
+  }
+
+  @Test
+  public void testValidEncryptionDecryption() throws IOException {
+    pinotCrypter.encrypt(srcFile, encryptedFile);
+    pinotCrypter.decrypt(encryptedFile, decryptedFile);
+    Assert.assertTrue(FileUtils.contentEquals(srcFile, decryptedFile));
+  }
+
+  @Test
+  public void testInvalidEncryption() throws IOException {
+    srcFile = new File("fake");
+    pinotCrypter.encrypt(srcFile, decryptedFile);
+    Assert.assertFalse(decryptedFile.exists());

Review comment:
       Isn't `decryptedFile` already created in init()? Which also brings up the point that the files created in `init()` would only end up being used in one of the tests, so what's the purpose of creating them in `init()`?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] kishoreg commented on a change in pull request #5726: Adding Test coverage to NoOpPinotCrypt class

Posted by GitBox <gi...@apache.org>.
kishoreg commented on a change in pull request #5726:
URL: https://github.com/apache/incubator-pinot/pull/5726#discussion_r458565075



##########
File path: pinot-spi/src/test/java/org/apache/pinot/spi/crypt/NoOpPinotCryptTest.java
##########
@@ -0,0 +1,63 @@
+/**
+ * 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.pinot.spi.crypt;
+
+import java.io.File;
+import java.io.IOException;
+import org.apache.commons.io.FileUtils;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class NoOpPinotCryptTest {
+
+  PinotCrypter pinotCrypter;
+  File srcFile;
+  File destinationFile;
+  @BeforeTest
+  public void init() throws IOException {
+    pinotCrypter = new NoOpPinotCrypter();
+    srcFile = File.createTempFile("srcFile","txt");

Review comment:
       can we use names like encryptedFile and decryptedFile for readability




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org