Skip to content

Commit

Permalink
Merge remote-tracking branch 'apache/master' into HEAD
Browse files Browse the repository at this point in the history
Change-Id: Iaf2b997ba214db59f897fa430328356f0e8f1f47

# Conflicts:
#	hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/validation/VersionExtractor.java
#	hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/validation/TestVersionExtractor.java
  • Loading branch information
swamirishi committed Dec 20, 2024
2 parents 4004663 + 7af38a9 commit 2337f72
Show file tree
Hide file tree
Showing 19 changed files with 680 additions and 358 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import java.lang.reflect.Modifier;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import static java.nio.charset.StandardCharsets.UTF_8;
Expand Down Expand Up @@ -353,86 +355,88 @@ private static long monotonicNow() {
return System.nanoTime() / NANOSECONDS_PER_MILLISECOND;
}

/**
* Capture output printed to {@link System#err}.
* <p>
* Usage:
* <pre>
* try (SystemErrCapturer capture = new SystemErrCapturer()) {
* ...
* // Call capture.getOutput() to get the output string
* }
* </pre>
* <p>
* TODO: Add lambda support once Java 8 is common.
* {@code
* SystemErrCapturer.withCapture(capture -> {
* ...
* })
* }
*/
public static class SystemErrCapturer implements AutoCloseable {
public static PrintStreamCapturer captureOut() {
return new SystemOutCapturer();
}

public static PrintStreamCapturer captureErr() {
return new SystemErrCapturer();
}

/** Capture contents of a {@code PrintStream}, until {@code close()}d. */
public abstract static class PrintStreamCapturer implements AutoCloseable, Supplier<String> {
private final ByteArrayOutputStream bytes;
private final PrintStream bytesPrintStream;
private final PrintStream oldErr;
private final PrintStream old;
private final Consumer<PrintStream> restore;

public SystemErrCapturer() throws UnsupportedEncodingException {
protected PrintStreamCapturer(PrintStream out, Consumer<PrintStream> install) {
old = out;
bytes = new ByteArrayOutputStream();
bytesPrintStream = new PrintStream(bytes, false, UTF_8.name());
oldErr = System.err;
System.setErr(new TeePrintStream(oldErr, bytesPrintStream));
try {
bytesPrintStream = new PrintStream(bytes, false, UTF_8.name());
install.accept(new TeePrintStream(out, bytesPrintStream));
restore = install;
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}

@Override
public String get() {
return getOutput();
}

public String getOutput() {
try {
return bytes.toString(UTF_8.name());
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}

public String getOutput() throws UnsupportedEncodingException {
return bytes.toString(UTF_8.name());
public void reset() {
bytes.reset();
}

@Override
public void close() throws Exception {
IOUtils.closeQuietly(bytesPrintStream);
System.setErr(oldErr);
restore.accept(old);
}
}

/**
* Capture output printed to {@link System#out}.
* Capture output printed to {@link System#err}.
* <p>
* Usage:
* <pre>
* try (SystemOutCapturer capture = new SystemOutCapturer()) {
* try (PrintStreamCapturer capture = captureErr()) {
* ...
* // Call capture.getOutput() to get the output string
* }
* </pre>
* <p>
* TODO: Add lambda support once Java 8 is common.
* {@code
* SystemOutCapturer.withCapture(capture -> {
* ...
* })
* }
*/
public static class SystemOutCapturer implements AutoCloseable {
private final ByteArrayOutputStream bytes;
private final PrintStream bytesPrintStream;
private final PrintStream oldOut;

public SystemOutCapturer() throws
UnsupportedEncodingException {
bytes = new ByteArrayOutputStream();
bytesPrintStream = new PrintStream(bytes, false, UTF_8.name());
oldOut = System.out;
System.setOut(new TeePrintStream(oldOut, bytesPrintStream));
}

public String getOutput() throws UnsupportedEncodingException {
return bytes.toString(UTF_8.name());
public static class SystemErrCapturer extends PrintStreamCapturer {
public SystemErrCapturer() {
super(System.err, System::setErr);
}
}

@Override
public void close() throws Exception {
IOUtils.closeQuietly(bytesPrintStream);
System.setOut(oldOut);
/**
* Capture output printed to {@link System#out}.
* <p>
* Usage:
* <pre>
* try (PrintStreamCapturer capture = captureOut()) {
* ...
* // Call capture.getOutput() to get the output string
* }
* </pre>
*/
public static class SystemOutCapturer extends PrintStreamCapturer {
public SystemOutCapturer() {
super(System.out, System::setOut);
}
}

Expand Down
2 changes: 1 addition & 1 deletion hadoop-ozone/dist/src/main/smoketest/createmrenv.robot
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Create volume
${result} = Execute ozone sh volume create /${volume} --user hadoop --space-quota 100TB --namespace-quota 100
Should not contain ${result} Failed
Create bucket
Execute ozone sh bucket create /${volume}/${bucket} --space-quota 1TB --layout FILE_SYSTEM_OPTIMIZED
Execute ozone sh bucket create /${volume}/${bucket} --space-quota 1TB --layout fso

*** Test Cases ***
Create test volume, bucket and key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ${TESTFILE} testfile
Write keys
Run Keyword if '${SECURITY_ENABLED}' == 'true' Kinit test user testuser testuser.keytab
Execute ozone sh volume create ${VOLUME}
Execute ozone sh bucket create ${VOLUME}/${BUCKET} -l OBJECT_STORE
Execute ozone sh bucket create ${VOLUME}/${BUCKET} -l obs
Execute dd if=/dev/urandom of=${TEMP_DIR}/${TESTFILE}1 bs=100 count=10
Execute ozone sh key put ${VOLUME}/${BUCKET}/${TESTFILE}1 ${TEMP_DIR}/${TESTFILE}1
Execute dd if=/dev/urandom of=${TEMP_DIR}/${TESTFILE}2 bs=100 count=15
Expand Down
Loading

0 comments on commit 2337f72

Please sign in to comment.