You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2022/01/09 08:23:21 UTC

[GitHub] [cassandra] nvharikrishna opened a new pull request #1381: [CASSANDRA-17126] Removing usages of java.io.File and others from tests

nvharikrishna opened a new pull request #1381:
URL: https://github.com/apache/cassandra/pull/1381


   Replaced the usages of java.io.File, java.io.FileInputStream, java.io.FileOutputStream, java.io.FileWriter and java.io.RandomAccessFile from tests.
   
   Could not find alternative to RandomAccessFile.setLength(), so added checkstyle exceptions.


-- 
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.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] nvharikrishna commented on a change in pull request #1381: [CASSANDRA-17126] Removing usages of java.io.File and others from tests

Posted by GitBox <gi...@apache.org>.
nvharikrishna commented on a change in pull request #1381:
URL: https://github.com/apache/cassandra/pull/1381#discussion_r793351003



##########
File path: test/unit/org/apache/cassandra/Util.java
##########
@@ -850,4 +853,25 @@ public static void setUpgradeFromVersion(String version)
         }
         Gossiper.instance.expireUpgradeFromVersion();
     }
+
+    /**
+     * Sets the length of the file to given size. File will be created if not exist.
+     * @param file file for which length needs to be set
+     * @param size new szie
+     * @throws IOException on any I/O error.
+     */
+    public static void setFileLength(File file, long size) throws IOException
+    {
+        try(FileChannel fileChannel = file.newReadWriteChannel()) {
+            if(file.length() >= size)
+            {
+                fileChannel.truncate(size);
+            }
+            else
+            {
+                fileChannel.position(size -1);

Review comment:
       done

##########
File path: test/long/org/apache/cassandra/cql3/CorruptionTest.java
##########
@@ -145,10 +145,10 @@ private void dumpKeys(byte[] putdata, byte[] getdata) throws IOException {
                     String basename = "bad-data-tid" + Thread.currentThread().getId();
                     File put = new File(basename+"-put");
                     File get = new File(basename+"-get");
-                    try(FileWriter pw = new FileWriter(put.toJavaIOFile())) {
+                    try(FileWriter pw = put.newWriter(File.WriteMode.OVERWRITE)) {

Review comment:
       done




-- 
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.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] smiklosovic closed pull request #1381: [CASSANDRA-17126] Removing usages of java.io.File and others from tests

Posted by GitBox <gi...@apache.org>.
smiklosovic closed pull request #1381:
URL: https://github.com/apache/cassandra/pull/1381


   


-- 
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.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] nvharikrishna commented on pull request #1381: [CASSANDRA-17126] Removing usages of java.io.File and others from tests

Posted by GitBox <gi...@apache.org>.
nvharikrishna commented on pull request #1381:
URL: https://github.com/apache/cassandra/pull/1381#issuecomment-1022542821


   Made code changes (by using position + write a byte) to set length of a file and removed checkstyle exceptions for RandomAccessFile except one place: org.apache.cassandra.io.compress.CompressedRandomAccessReaderTest#updateChecksum which is using FileDescriptor.


-- 
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.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] bereng commented on a change in pull request #1381: [CASSANDRA-17126] Removing usages of java.io.File and others from tests

Posted by GitBox <gi...@apache.org>.
bereng commented on a change in pull request #1381:
URL: https://github.com/apache/cassandra/pull/1381#discussion_r793296608



##########
File path: build.xml
##########
@@ -2223,6 +2223,7 @@
           <formatter type="plain"/>
           <formatter type="xml" tofile="${checkstyle.report.file}"/>
           <fileset dir="${build.src.java}" includes="**/*.java"/>
+          <!--<fileset dir="${test.dir}" includes="**/*.java"/>-->

Review comment:
       Left-over?




-- 
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.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] nvharikrishna commented on a change in pull request #1381: [CASSANDRA-17126] Removing usages of java.io.File and others from tests

Posted by GitBox <gi...@apache.org>.
nvharikrishna commented on a change in pull request #1381:
URL: https://github.com/apache/cassandra/pull/1381#discussion_r793353182



##########
File path: build.xml
##########
@@ -2223,6 +2223,7 @@
           <formatter type="plain"/>
           <formatter type="xml" tofile="${checkstyle.report.file}"/>
           <fileset dir="${build.src.java}" includes="**/*.java"/>
+          <!--<fileset dir="${test.dir}" includes="**/*.java"/>-->

Review comment:
       Left it intentionally as there are two more tickets on the same line (thought it might be useful). I can remove, if you find it not useful.




-- 
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.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] driftx commented on a change in pull request #1381: [CASSANDRA-17126] Removing usages of java.io.File and others from tests

Posted by GitBox <gi...@apache.org>.
driftx commented on a change in pull request #1381:
URL: https://github.com/apache/cassandra/pull/1381#discussion_r793579778



##########
File path: build.xml
##########
@@ -2223,6 +2223,7 @@
           <formatter type="plain"/>
           <formatter type="xml" tofile="${checkstyle.report.file}"/>
           <fileset dir="${build.src.java}" includes="**/*.java"/>
+          <!--<fileset dir="${test.dir}" includes="**/*.java"/>-->

Review comment:
       I was going to remove it on commit, no worries.




-- 
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.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] driftx commented on pull request #1381: [CASSANDRA-17126] Removing usages of java.io.File and others from tests

Posted by GitBox <gi...@apache.org>.
driftx commented on pull request #1381:
URL: https://github.com/apache/cassandra/pull/1381#issuecomment-1021559047


   I think we are only using setLength() to set the size, and not truncate to that size, so we should be able to implement that ourselves if necessary to avoid the checkstyle exceptions.


-- 
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.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] bereng commented on a change in pull request #1381: [CASSANDRA-17126] Removing usages of java.io.File and others from tests

Posted by GitBox <gi...@apache.org>.
bereng commented on a change in pull request #1381:
URL: https://github.com/apache/cassandra/pull/1381#discussion_r793296977



##########
File path: test/long/org/apache/cassandra/cql3/CorruptionTest.java
##########
@@ -145,10 +145,10 @@ private void dumpKeys(byte[] putdata, byte[] getdata) throws IOException {
                     String basename = "bad-data-tid" + Thread.currentThread().getId();
                     File put = new File(basename+"-put");
                     File get = new File(basename+"-get");
-                    try(FileWriter pw = new FileWriter(put.toJavaIOFile())) {
+                    try(FileWriter pw = put.newWriter(File.WriteMode.OVERWRITE)) {

Review comment:
       Formatting: While we are here can we put the brace in the next line?




-- 
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.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] bereng commented on a change in pull request #1381: [CASSANDRA-17126] Removing usages of java.io.File and others from tests

Posted by GitBox <gi...@apache.org>.
bereng commented on a change in pull request #1381:
URL: https://github.com/apache/cassandra/pull/1381#discussion_r793297388



##########
File path: test/unit/org/apache/cassandra/Util.java
##########
@@ -850,4 +853,25 @@ public static void setUpgradeFromVersion(String version)
         }
         Gossiper.instance.expireUpgradeFromVersion();
     }
+
+    /**
+     * Sets the length of the file to given size. File will be created if not exist.
+     * @param file file for which length needs to be set
+     * @param size new szie
+     * @throws IOException on any I/O error.
+     */
+    public static void setFileLength(File file, long size) throws IOException
+    {
+        try(FileChannel fileChannel = file.newReadWriteChannel()) {
+            if(file.length() >= size)
+            {
+                fileChannel.truncate(size);
+            }
+            else
+            {
+                fileChannel.position(size -1);

Review comment:
       Formating

##########
File path: test/unit/org/apache/cassandra/Util.java
##########
@@ -850,4 +853,25 @@ public static void setUpgradeFromVersion(String version)
         }
         Gossiper.instance.expireUpgradeFromVersion();
     }
+
+    /**
+     * Sets the length of the file to given size. File will be created if not exist.
+     * @param file file for which length needs to be set
+     * @param size new szie
+     * @throws IOException on any I/O error.
+     */
+    public static void setFileLength(File file, long size) throws IOException
+    {
+        try(FileChannel fileChannel = file.newReadWriteChannel()) {
+            if(file.length() >= size)
+            {
+                fileChannel.truncate(size);
+            }
+            else
+            {
+                fileChannel.position(size -1);

Review comment:
       Formatting




-- 
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.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org