Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3148 chRemote #3149

Merged
merged 5 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -25,7 +25,6 @@

import com.jcabi.log.Logger;
import org.cactoos.Text;
import org.cactoos.text.Sticky;

/**
* Hash of tag from objectionary.
Expand All @@ -37,7 +36,7 @@ public final class ChRemote implements CommitHash {
/**
* Cached text of hashes.
*/
private static final Text CACHE = new Sticky(new CommitHashesText());
private static final Text CACHE = new CommitHashesText();

/**
* Tag.
Expand Down
Expand Up @@ -23,12 +23,15 @@
*/
package org.eolang.maven.hash;

import org.cactoos.Scalar;

/**
* Hash of tag.
*
* @since 0.28.11
*/
public interface CommitHash {
@FunctionalInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@levBagryansky why do we need it here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxonfjvipon I added it because this actually is a functional interface.

public interface CommitHash extends Scalar<String> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxonfjvipon I inhereted it firstly because it has the same method so it really can be inherited. Also it allowed to write

                    Stream.generate(
                        () -> new ChRemote("0.23.19")
                    ).limit(threads).collect(Collectors.toList())

and this is cool.


/**
* SHA Hash.
Expand Down
Expand Up @@ -25,6 +25,10 @@
package org.eolang.maven.hash;

import com.yegor256.WeAreOnline;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.cactoos.experimental.Threads;
import org.eolang.maven.BinarizeParseTest;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
Expand Down Expand Up @@ -67,4 +71,22 @@ void throwsCommitHashException() {
BinarizeParseTest.TO_ADD_MESSAGE
);
}

@Test
void isThreadSafe() {
final int threads = 200;
final String sample = new ChRemote("0.23.19").value();
MatcherAssert.assertThat(
"You can use this class concurrently",
StreamSupport.stream(
new Threads<>(
threads,
Stream.generate(
() -> new ChRemote("0.23.19")
).limit(threads).collect(Collectors.toList())
).spliterator(), false
).filter(str -> !sample.equals(str)).collect(Collectors.toList()),
Matchers.empty()
);
}
}