diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..5ff6309b7199129c1afe4f4ec1906e640bec48c6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/data_types/pom.xml b/data_types/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..49bdf9fd4de08794ccec72a087f955819ebacde8 --- /dev/null +++ b/data_types/pom.xml @@ -0,0 +1,60 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.example</groupId> + <artifactId>data_types</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <name>hello</name> + <url>http://maven.apache.org</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>redis.clients</groupId> + <artifactId>jedis</artifactId> + <version>5.1.5</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>2.0.16</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <version>2.0.16</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.13.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest</artifactId> + <version>2.2</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>4.7.0</version> + <scope>test</scope> + </dependency> + + </dependencies> +</project> diff --git a/data_types/src/test/java/org/example/JedisBasicsTest.java b/data_types/src/test/java/org/example/JedisBasicsTest.java new file mode 100644 index 0000000000000000000000000000000000000000..26e06503f769e8aef78a739c65f8a832b0a9f239 --- /dev/null +++ b/data_types/src/test/java/org/example/JedisBasicsTest.java @@ -0,0 +1,133 @@ +package org.example; + +import org.junit.*; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPoolConfig; + +import java.util.*; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +public class JedisBasicsTest { + // TODO: Replace the following with your own Redis configuration + final private static String host = "<your redis host>"; + final private static Integer port = 0; // your port number + final private static String password = "<your password>"; + final private static Integer timeout = 2000; + + public static String[] testPlanets = { "Mercury", "Mercury", "Venus", + "Earth", "Earth", "Mars", + "Jupiter", "Saturn", "Uranus", + "Neptune", "Pluto" }; + + private JedisPoolConfig config; + private JedisPool pool; + private Jedis jedis; + + @Before + public void setUp() { + this.config = new JedisPoolConfig(); + + this.pool = new JedisPool(config, host, port, timeout, password); + this.jedis = pool.getResource(); + + jedis.del("planets"); + jedis.del("earth"); + } + + @After + public void tearDown() { + jedis.del("planets"); + jedis.del("earth"); + jedis.close(); + } + + @Test + public void testRedisList() { + assertThat(testPlanets.length, is(11)); + + /* Add all test planets to the Redis set */ + Long result = null; // TODO + assertThat(result, is(11L)); + + // Check the length of the list + Long length = null; // TODO + assertThat(length, is(11L)); + + // Get the planets from the list + // Note: LRANGE is an O(n) command. Be careful running this command + // with high-cardinality sets. + List<String> planets = null; // TODO + assertThat(planets, is(Arrays.asList(testPlanets))); + + // Remove the elements that we know are duplicates + // Note: O(n) operation. + // TODO + + + // Drop a planet from the end of the list + String planet = null; // TODO + assertThat(planet, is("Pluto")); + + assertThat(jedis.llen("planets"), is(8L)); + } + + @Test + public void testRedisSet() { + assertThat(testPlanets.length, is(11)); + + // Add all test planets to the Redis set + // TODO + + // Return the cardinality of the set + Long length = null; // TODO + assertThat(length, is(9L)); + + // Fetch all values from the set + // Note: SMEMBERS is an O(n) command. Be careful running this command + // with high-cardinality sets. Consider SSCAN as an alternative. + Set<String> planets = null; // TODO + + // Ensure that a HashSet created and stored in Java memory and the set stored + // in Redis have the same values. + Set<String> planetSet = new HashSet<>(Arrays.asList(testPlanets)); + assertThat(planets, is(planetSet)); + + // Pluto is, of course, no longer a first-class planet. Remove it. + Long response = null; // TODO + assertThat(response, is(1L)); + + // Now we have 8 planets, as expected. + Long newLength = null; // TODO + assertThat(newLength, is(8L)); + } + + @Test + public void testRedisHash() { + Map<String, String> earthProperties = new HashMap<>(); + earthProperties.put("diameterKM", "12756"); + earthProperties.put("dayLengthHrs", "24"); + earthProperties.put("meanTempC", "15"); + earthProperties.put("moonCount", "1"); + + // Set the fields of the hash one by one. + for (Map.Entry<String, String> property : earthProperties.entrySet()) { + // TODO + } + + // Get the hash we just created back from Redis. + Map<String, String> storedProperties = null; // TODO + assertThat(storedProperties, is(earthProperties)); + + // Setting fields all at once is more efficient. + // TODO + storedProperties = null; // TODO + assertThat(storedProperties, is(earthProperties)); + + // Test that we can get a single property. + String diameter = null; // TODO + assertThat(diameter, is(earthProperties.get("diameterKM"))); + } +} diff --git a/hello/pom.xml b/hello/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..8c7949d7e590c5baa912cbfb5af40a05bc2a1550 --- /dev/null +++ b/hello/pom.xml @@ -0,0 +1,41 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.example</groupId> + <artifactId>hello</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <name>hello</name> + <url>http://maven.apache.org</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>redis.clients</groupId> + <artifactId>jedis</artifactId> + <version>5.1.5</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>2.0.16</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <version>2.0.16</version> + <scope>runtime</scope> + </dependency> + </dependencies> +</project> diff --git a/hello/src/main/java/org/example/App.java b/hello/src/main/java/org/example/App.java new file mode 100644 index 0000000000000000000000000000000000000000..2f1482a27a4579a9cf62e6f81d3433cee459d0e0 --- /dev/null +++ b/hello/src/main/java/org/example/App.java @@ -0,0 +1,24 @@ +package org.example; + +import redis.clients.jedis.*; + +public class App { + // TODO: Replace the following with your own Redis configuration + final private static String host = "<your redis host>"; + final private static Integer port = 0; // your port number + final private static String password = "<your password>"; + final private static Integer timeout = 2000; + + public static void main(String[] args) { + JedisPoolConfig config = new JedisPoolConfig(); + + JedisPool pool = new JedisPool(config, host, port, timeout, password); + Jedis jedis = pool.getResource(); + jedis.set("foo", "bar"); + String value = jedis.get("foo"); + System.out.println(value); + pool.close(); + } +} + + diff --git a/hello/src/test/java/org/example/AppTest.java b/hello/src/test/java/org/example/AppTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d5f435df0340a1f8b4f2cd9b9d6220ffd05c2d21 --- /dev/null +++ b/hello/src/test/java/org/example/AppTest.java @@ -0,0 +1,38 @@ +package org.example; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +}