├── .gitignore ├── README.md ├── pom.xml └── src ├── main └── java │ └── net │ └── intelie │ └── challenges │ ├── Event.java │ ├── EventIterator.java │ └── EventStore.java └── test └── java └── net └── intelie └── challenges └── EventTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | *.ipr 3 | *.iws 4 | *.log 5 | *.versionsBackup 6 | *.swp 7 | .ideas 8 | .idea 9 | .DS_Store 10 | .attach 11 | *.hprof 12 | /target 13 | /*/target 14 | /trace.db 15 | .jhw-cache 16 | dependency-reduced-pom.xml 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Implement EventStore 2 | 3 | In this challenge, you will create a class that implements the `EventStore` 4 | interface. 5 | 6 | ```java 7 | public interface EventStore { 8 | void insert(Event event); 9 | 10 | void removeAll(String type); 11 | 12 | EventIterator query(String type, long startTime, long endTime); 13 | } 14 | ``` 15 | 16 | Your implementation should store events in memory, using any data structures 17 | you see fit for the task. The required behavior for the interface is described in the 18 | provided code javadocs, please see `EventStore` and `EventIterator` 19 | interfaces inside the `src/main/java` directory. 20 | 21 | The implementation should be correct, fast, memory-efficient, and thread-safe. 22 | You may consider that insertions, deletions, queries, and iterations 23 | will happen frequently and concurrently. This will be a system hotspot. Optimize at will. 24 | 25 | We expect you to: 26 | * Write tests; 27 | * Provide some evidence of thread-safety; 28 | * Justify design choices, arguing about costs 29 | and benefits involved. You may write those as comments 30 | inline or, if you wish, provide a separate document 31 | summarizing those choices; 32 | * Write all code and documentation in english. 33 | 34 | You may use external libraries, but their use has to be 35 | properly justified as well. 36 | 37 | This challenge is intentionally simple, we expect a simple, 38 | elegant, and polished solution. There is no unique solution to this challenge. 39 | The intent is to evaluate candidate's coding proficiency and familiarity with 40 | tools and best practices. 41 | 42 | 43 | ## Solve this challenge 44 | 45 | To solve this challenge, you may fork this repository, then 46 | send us a link with your implementation. Alternatively, if you do not want to have this repo on 47 | your profile (we totally get it), send us a 48 | [git patch file](https://www.devroom.io/2009/10/26/how-to-create-and-apply-a-patch-with-git/) 49 | with your changes. 50 | 51 | If you are already in the hiring process, you may send it to 52 | whoever is your contact at Intelie. If you wish to apply for a job at 53 | Intelie, please send your solution to [trabalhe@intelie.com.br](mailto:trabalhe@intelie.com.br). 54 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | net.intelie.interview 8 | challenge-eventstore 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | 14 | junit 15 | junit 16 | 4.13.1 17 | test 18 | 19 | 20 | 21 | 22 | 23 | 24 | org.apache.maven.plugins 25 | maven-compiler-plugin 26 | 3.2 27 | 28 | 1.8 29 | 1.8 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/main/java/net/intelie/challenges/Event.java: -------------------------------------------------------------------------------- 1 | package net.intelie.challenges; 2 | 3 | /** 4 | * This is just an event stub, feel free to expand it if needed. 5 | */ 6 | public class Event { 7 | private final String type; 8 | private final long timestamp; 9 | 10 | public Event(String type, long timestamp) { 11 | this.type = type; 12 | this.timestamp = timestamp; 13 | } 14 | 15 | public String type() { 16 | return type; 17 | } 18 | 19 | public long timestamp() { 20 | return timestamp; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/intelie/challenges/EventIterator.java: -------------------------------------------------------------------------------- 1 | package net.intelie.challenges; 2 | 3 | /** 4 | * An iterator over an event collection. 5 | */ 6 | public interface EventIterator extends AutoCloseable { 7 | /** 8 | * Move the iterator to the next event, if any. 9 | * 10 | * @return false if the iterator has reached the end, true otherwise. 11 | */ 12 | boolean moveNext(); 13 | 14 | /** 15 | * Gets the current event ref'd by this iterator. 16 | * 17 | * @return the event itself. 18 | * @throws IllegalStateException if {@link #moveNext} was never called 19 | * or its last result was {@code false}. 20 | */ 21 | Event current(); 22 | 23 | /** 24 | * Remove current event from its store. 25 | * 26 | * @throws IllegalStateException if {@link #moveNext} was never called 27 | * or its last result was {@code false}. 28 | */ 29 | void remove(); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/intelie/challenges/EventStore.java: -------------------------------------------------------------------------------- 1 | package net.intelie.challenges; 2 | 3 | /** 4 | * An abstraction of an event store. 5 | *

6 | * Events may be stored in memory, data files, a database, on a remote 7 | * server, etc. For this challenge, you should implement an in-memory 8 | * event event store. 9 | */ 10 | public interface EventStore { 11 | /** 12 | * Stores an event 13 | * 14 | * @param event 15 | */ 16 | void insert(Event event); 17 | 18 | 19 | /** 20 | * Removes all events of specific type. 21 | * 22 | * @param type 23 | */ 24 | void removeAll(String type); 25 | 26 | /** 27 | * Retrieves an iterator for events based on their type and timestamp. 28 | * 29 | * @param type The type we are querying for. 30 | * @param startTime Start timestamp (inclusive). 31 | * @param endTime End timestamp (exclusive). 32 | * @return An iterator where all its events have same type as 33 | * {@param type} and timestamp between {@param startTime} 34 | * (inclusive) and {@param endTime} (exclusive). 35 | */ 36 | EventIterator query(String type, long startTime, long endTime); 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/net/intelie/challenges/EventTest.java: -------------------------------------------------------------------------------- 1 | package net.intelie.challenges; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | public class EventTest { 8 | @Test 9 | public void thisIsAWarning() throws Exception { 10 | Event event = new Event("some_type", 123L); 11 | 12 | //THIS IS A WARNING: 13 | //Some of us (not everyone) are coverage freaks. 14 | assertEquals(123L, event.timestamp()); 15 | assertEquals("some_type", event.type()); 16 | } 17 | } --------------------------------------------------------------------------------